Optional Message Parts in WSDL

10,240

Solution 1

In WSDL parts can not be optional. They are always required. If you need optional parts, you will have to create one part that refers to a XSD complexType that then can have optional elements.

Solution 2

You can add nullable to lastname, so firstname is required:

<message name="setName">
    <part name="firstname" type="xsd:string"></part>
    <part name="lastname" xsi:nil="true" type="xsd:string"></part>
</message> 

If you do so, your soap body look like this (empty or filled lastname):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:user="http://www.example.com/MyService/">
   <soapenv:Header/>
   <soapenv:Body>
      <user:setName>
         <firstname>John</firstname>
         <lastname></lastname>
      </user:setName>
   </soapenv:Body>
</soapenv:Envelope>

Or even without lastname:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:user="http://www.example.com/MyService/">
   <soapenv:Header/>
   <soapenv:Body>
      <user:setName>
         <firstname>John</firstname>
      </user:setName>
   </soapenv:Body>
</soapenv:Envelope>
Share:
10,240

Related videos on Youtube

mosch
Author by

mosch

Updated on June 04, 2022

Comments

  • mosch
    mosch almost 2 years

    In my wsdl:message i got two parameters, firstname and lastname:

    <message name="setName">
      <part name="firstname" type="xsd:string"></part>
      <part name="lastname" type="xsd:string"></part>
    </message> 
    

    I want to define the "firstname" part as required, and the "lastname" part as optional. How do i do that?

  • Pwnstar
    Pwnstar about 7 years
    Example ? Nobody which is new to this topic can understand what you mean
  • xhienne
    xhienne over 5 years
    You will have to add the namespace definition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" to your WSDL for xsi:nil to be understood.
  • Laurent Grégoire
    Laurent Grégoire almost 5 years
    W/o lastname, does not seem to work, at least using Apache CXF.
  • Jonas_Hess
    Jonas_Hess over 3 years
    Example can be found here: stackoverflow.com/questions/21179098/…