function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Frédéric ProvotFrédéric Provot 

Login to SF by webservice : Web service callout failed: Failed to get next element : MTOM?

Hello everybody
After having generated Apex classes with the salesforce partner WSDL, I can call the login method to connect to my saleforce instance.

But the answer to login command seems to be incompatible, although it is done by the WebServiceCallout.invoke salesforce command and response generated by my saleforce sandbox, which is the same as the client!
 
partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult loginResult = sp.login('xxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxx');

=> this calls WebServiceCallout.invoke , which throws an exception :
|CALLOUT_REQUEST|[3238]|login_element:[apex_schema_type_info=(urn:partner.soap.sforce.com, true, false), field_order_type_info=(username, password), password=dzEq36OXdHH4ld4klMHjmXbDp4J8Vvlli40WuLQKBorauosLcXwY8umcXMnkXzxj, password_type_info=(password, urn:partner.soap.sforce.com, null, 1, 1, false), username=theusername@besancon.parkeon.com.devstorage, username_type_info=(username, urn:partner.soap.sforce.com, null, 1, 1, false)]::SOAPAction="" Accept=text/xml User-Agent=SFDC-Callout/36.0 SFDC_STACK_DEPTH=1 Content-Type=text/xml; charset=UTF-8
10:52:29.1 (220486436)|EXCEPTION_THROWN|[3238]|System.CalloutException: Web service callout failed: Failed to get next element

Of course I've read every post I've found about this error. The most interesting are those ones:
https://developer.salesforce.com/forums/?id=906F0000000ApX7IAK
https://developer.salesforce.com/forums/?id=906F000000093OlIAI
The two here points me to the SOAP MTOM content format. Il seems then to me that the server uses MTOM to answer, but the client (which is the same server) can't handle it. Or the opposite!

I haven't found out how I can disable MTOM, programatically or by configuration.
Does partnerSoapSforceCom.Soap allow to enable/disable MTOM? What is the command? A header setting?

Hoping someone can help,
Best regards
Frederic
Daniel BallingerDaniel Ballinger
Did you use the native version of Wsdl2Apex to import the Partner API into Apex?

I've made an alternative free version that will likely have more success with the login API call. See FuseIT SFDC Explorer (http://www.fuseit.com/explorer)

The following was executed from anonymous Apex using the Partner API from v36.0.
partnerSoapSforceCom.Soap partner = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult lr=partner.login('username@example.com', 'Password+SecurityToken');
partnerSoapSforceCom.SessionHeader_element header=new partnerSoapSforceCom.SessionHeader_element();
header.sessionId=lr.sessionId;
partner.SessionHeader=header;
partner.endpoint_x = lr.serverUrl;
partnerSoapSforceCom.QueryResult qr = partner.Query('Select Id from Account limit 1');
System.debug('Number of Query results:' + qr);
sobjectPartnerSoapSforceCom.sObject_x result1 = qr.records[0];
System.debug(result1);



 
Frédéric ProvotFrédéric Provot

Hello Daniel,
I used saleforce's class generation from WSDL indeed, the button in Apex Class page. 
I tried your software, which is very interesting. But the result was finaly the same : I was still getting "Failed to get next element" at exit of method partnerSoapSforceCom.Soap.login(String, String), even with your code example. 

Though with you example I had to add 
partner.endpoint_x= System.Url.getSalesforceBaseURL().toExternalForm() + '/services/data/v36.0/limits' which pointed me to figure out that this could be an issue.
And it was. Using System.Url.getSalesforceBaseURL().toExternalForm() + '/services/Soap/u/36.0' the login succeeded !

So my problem is resolved! Thanks a lot for your help.

By the way, some considerations on your tool : 

  • The FuseIT generation action gives an error : cannot cast 'System.Xml.Linq.XComment' to type 'System.Xml.Linq.XElement'.
  • This error is not commented out in the generated class.
  • Generation of the classes is well done. But if I filter to login method only a lot of objects are missing in the Soap class like SessionHeader for example. I guess I should generate step by step adding objects until every necessary object is present (to avoid the big class).
  • The automatic generation of mock classes is a very good point.
  • FuseIT crashes a lot! I finally copy/paste the code, then modify it in eclipse and save the result to the sandbox.
  • Also i couldn't save a login profile.
  • Test runs from FuseIT seems something interesting i've not yet tried.
Best regards
Frederic