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>
Related videos on Youtube
Author by
mosch
Updated on June 04, 2022Comments
-
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 about 7 yearsExample ? Nobody which is new to this topic can understand what you mean
-
xhienne over 5 yearsYou will have to add the namespace definition
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
to your WSDL forxsi:nil
to be understood. -
Laurent Grégoire almost 5 yearsW/o lastname, does not seem to work, at least using Apache CXF.
-
Jonas_Hess over 3 yearsExample can be found here: stackoverflow.com/questions/21179098/…