SOAP XML Property Order is Important


When you construct a SOAP message yourself, when using Perl, for instance, the order of the properties within the SOAP XML element is critical. For example, the UserCredentials type has two properties, Username and Password. The SOAP XML for an instance of this type would look like this:


<UserCredentials xmlns="https://adcenter.microsoft.com/api/advertiser/v5">
  <Password>My_Password</Password>
  <Username>My_Username</Username>
</UserCredentials>

Notice that the Password property is first, followed by Username. The order of the properties in the XML is important because the adCenter deserializer will not interpret the contents of the element correctly if the properties are not in the correct order.

You can determine the correct order of the properties from the WSDL. For example, the following is the definition of the UserCredentials type in https://adcenterapi.microsoft.com/Api/Advertiser/V5/CampaignManagement/CampaignManagementService.svc?xsd=xsd0,

<xs:complexType name="UserCredentials">
  <xs:sequence>
    <xs:element minOccurs="0" name="Password" nillable="true" type="xs:string" />
    <xs:element minOccurs="0" name="Username" nillable="true" type="xs:string" />
  </xs:sequence>
</xs:complexType>

All types must be constructed in the sequence that they are specified.


To give another example, the KeywordBid type is defined as:


<xs:complexType name="KeywordBid">
  <xs:sequence>
    <xs:element minOccurs="0"
                name="BroadMatchBid"
                nillable="true"
                type="xs:double" />
    <xs:element minOccurs="0"
                name="ExactMatchBid"
                nillable="true"
                type="xs:double" />
    <xs:element name="Keyword"
                nillable="true"
                type="xs:string" />
    <xs:element minOccurs="0"
                name="PhraseMatchBid"
                nillable="true"
                type="xs:double" />
  </xs:sequence>
</xs:complexType>


This means that the properties for this type, if included, must be in the following order:


BroadMatchBid
ExactMatchBid
Keyword
PhraseMatchBid

Thank You,


Strohm Armstrong
Programming Writer - adCenter SDK

Comments (4)

  1. Anonymous says:

    There was a question during the Live Meeting this week regarding the correct sequence for SOAP XML elements

  2. Anonymous says:

    This is complete stupidity.

    If you enforce order, why do you enforce labeling?

    Why is your deserializer so fragile?

  3. Anonymous says:

    I just couldn?t leave your website before telling you that we really enjoyed the quality information you offer to your visitors? Will be back often to check up on new posts.

  4. john says:

    The order of elements in the soap xml is relevant only in as much the associated wsdl (through the xsd) enforces it so.

    The problem lies in the middleware implementations that generating service descriptors, usually from classes in a language, will specify a certain order. This is where most of the incompatibilities might arise from.

    Soap and XML per se don't enforce ordering of elements in any means.  

Skip to main content