Optional Message Parts in WSDL

前端 未结 2 1738
故里飘歌
故里飘歌 2021-01-04 04:20

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


  

相关标签:
2条回答
  • 2021-01-04 05:15

    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.

    0 讨论(0)
  • 2021-01-04 05:18

    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>
    
    0 讨论(0)
提交回复
热议问题