Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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>

share|improve this answer
    
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 Jan 25 '13 at 19:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.