14

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?

mosch
  • 1,005
  • 1
  • 12
  • 24

2 Answers2

17

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.

Tina
  • 202
  • 2
  • 3
5

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>
user8675
  • 657
  • 6
  • 13