简体   繁体   中英

How to handle minoccurs=“0” when calling web services?

I have a web service I am trying to call using a mainframe integration product (DataDirect Shadow z/Services), but my question is more of a general one. I want to know how an element defined as minOccurs="0" is typically handled. The operation on the 3rd party service I am calling has a complexType element where all of the elements within it are marked minOccurs="0".

Example from WSDL

<xs:element minOccurs="0" name="Request">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="startDate" type="xs:dateTime"/>
            <xs:element minOccurs="0" name="endDate" type="xs:dateTime"/>
            <xs:element minOccurs="0" name="requestId" type="tns:ObjectName"/>
            <xs:element minOccurs="0" name="reasonCode" type="xs:string"/>
            <xs:element minOccurs="0" name="actionType" type="xs:string"/>
            <xs:element minOccurs="0" maxOccurs="unbounded" name="option" type="xs:string"/>
            <xs:element minOccurs="0" name="comments" type="xs:string"/>
            <xs:element minOccurs="0" name="Name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

The way this service works on the other end, if a value is passed to the service, even if it is null or blank or default , the value will be updated on the 3rd party system. I need a way to OMIT that element in the payload to the service . How is that generally handled? I have tried using C# as a client for this service but the only thing I can find that they provide is the Specified suffixed variable for non-primitive types, but didn't find a way to omit primitive ones. If I was calling this web service by simply POST ing the SOAP message to the 3rd party server I could simply omit the XML for the value I did not want to pass, but I am just wondering how different web service client implementations handle this.

If it helps I believe the 3rd party is using Apache Axis and said they could omit the optional arguments.

When you tried POSTing with the xml part relating to the default/optional arg missing, did you notice any update for that arg at the server (apache axis) side? If you did, then it may be a problem with how the server-side logic had been implemented for that WSDL (not strictly respecting the contract/schema as defined by the WSDL).

I've worked with 3rd Party Web Services that require you to pass a value for all available tags that has a Specified parameter. You can pass pretty much anything in there as long as you set the Specified=false .

Usually you'll get your primitive types to have the Specified tag as well as handling types such as int, bool, double is a problem since they've got default values defined and not setting the Specified tag will cause those values to default to their default defined value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM