[SalesForce] SOAP XML node Sequence

So I recently had the task of logging in using the SOAP API. I constructed the envelope, and logged in fine with the following:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
       <soapenv:Body>
          <urn:login>
             <username>example@user.com</username>username>
             <password>password_token</password>
          </urn:login>
       </soapenv:Body>
    </soapenv:Envelope>

But when I move the username and password nodes around I get an fault saying that my username or password is incorrect.

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
       <soapenv:Body>
          <urn:login>
             <password>password_token</password>
             <username>example@user.com</username>username>
          </urn:login>
       </soapenv:Body>
    </soapenv:Envelope>

Is it common to enforce the XML structure like this? I used SOAPUI to test this.

Best Answer

It depends on the author of the Web Service or more specifically what is in the WSDL (Web Service Definition Language) they provide.

In most cases the receiving code (the web service implementation) does not get invoked until all of the XML in the SOAP envelope is unmarhsalled/deserialised and passed to it, so it should not really matter what order it arrived.

However it does seem that most Web Service providers these days do prefer to use the <xsd:sequence> element in my experience. When used in the WSDL that defines the web service, this implies the need for specific sequence none the less. And this is the standard Salesforce is using as well.

Looking at the Enterprise WSDL the login element does indeed use this, hence the behaviour your seeing.

<element name="login">

<complexType>

<sequence>

<element name="username" type="xsd:string"/>

<element name="password" type="xsd:string"/>

</sequence>

</complexType>

</element>