Nagoh
Nagoh

Reputation: 813

Ignoring XSD Sequence Order on Serialization in .NET

I am consuming a 3rd-party web service (of which, I have no control over) in .NET.

I noticed some of my properties were not being set when the response was returning and being serialized from the service.

I have noticed something strange with their response though.

This is a sample of their WSDL

<xs:complexType name="letters">
    <xs:complexContent>
        <xs:extension base="tns:response">
            <xs:sequence>
                <xs:element name="a" type="xs:long" />
                <xs:element minOccurs="0" name="b" type="xs:dateTime" />
                <xs:element maxOccurs="unbounded" minOccurs="0" name="c" nillable="true" type="tns:anotherComplexType" />
                <xs:element minOccurs="0" name="d" type="xs:dateTime" />
                <xs:element minOccurs="0" name="e" type="tns:string" />
                <xs:element minOccurs="0" name="f" type="tns:boolean" />
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

And this is a sample of the relevant part of the response:

<letters>
    <a>0</a>
    <b>2015-02-03T11:59:18+11:00</b>
    <d>2015-02-03T12:00:00+11:00</d>
    <f>true</f>
</letters>

I suspect that because they are defining a <xs:sequence> for the elements in the <letters> part, that the .NET Serializer is expecting the response to have ALL elements present in the response? (And thus, their response breaks their WSDL definition?).

Thanks

EDIT It appears that the response is returning an unknown element, specifically

<letters>
    <a>0</a>
    <b>2015-02-03T11:59:18+11:00</b>
    <d>2015-02-03T12:00:00+11:00</d>
    <otherElement>blue</otherElement>
    <f>true</f>
</letters>

Which is not part of the WSDL. This means that the <f> element is not being serialized. Is there a way for me to disregard unknown elements?

Upvotes: 1

Views: 415

Answers (1)

kjhughes
kjhughes

Reputation: 111726

No, xsd:sequence merely means that the elements must be in order. It is the @minOccurs attribute on each xs:element that indicates requiredness. When @minOccurs = 0, the element is optional. (Note that the default values for @minOccurs and @maxOccurs is 1, indicated "required".) Since many of the elements in that sequence are @minOccurs = 0, all elements do not have to be present in your response.

Upvotes: 1

Related Questions