3

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>[email protected]</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>[email protected]</username>username>
          </urn:login>
       </soapenv:Body>
    </soapenv:Envelope>

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

1 Answer 1

4

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>

1
  • Thanks for the explanation, very helpful. I was recently working on project that had used a third-party SOAP framework to generate SOAP envelopes. The issue I ran into was that the framework took arrays for arguments and then sorted them alphabetically, which was putting password above username. Since I could alter the tool I was using, nor alter the XML prior to request, I had to go a different. route. I'll know what to look for before I start another project now. Thank You.
    – fourq
    Commented Jan 25, 2013 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .