6

I have a problem with parsing a response I am receiving via a SOAP callout in Salesforce. The error I am receiving is : Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found 'http://schemas.xmlsoap.org/soap/envelope/:Fault'

One odd part of this is that the response is parsed fine when it is successful but when it faults, Salesforce does not know what to do with the response. I need those error messages so the end user can fix the issues and try again.

I have spoken with the tech in charge of the target system and he says the error responses are being sent correctly. Another oddity is that we have other similar webservices on the same system that are parsing errors perfectly. There seems to be no apparent differences in the Methods that were created by the WSDLs.

Does anyone have any thoughts as to why this error is occurring or does anyone have any tips to troubleshooting this issue.

Any suggestions are much appreciated. Thanks!

4

Can you enable the Apex Debug logs, these will show in outgoing and incoming XML for the callout. This should allow you to confirm more visually what the XML looks like.

Basically you should always have a soap:Envelope element, a soap:Fault element should always be within a soap:Body element. If you don't that is indeed invalid. If you have tested with other SOAP clients from other languages, try to capture the outgoing XML in those languages and compare with the debug you get from Apex.

As per the SOAP standard here.

If present, the SOAP Fault element MUST appear as a body entry and MUST NOT appear more than once within a Body element.

  • Thanks for answering Andrew! The problem was on our client's side. – Clark.Hruska Nov 12 '13 at 18:59
  • Ok glad you got it sorted, if this answer reflects the correct approach to resolving your question generally, please feel free to indicate as such by marking it as accepted for future readers. – Andrew Fawcett Nov 12 '13 at 19:34
2

Adding my own best answer, based on some internet research:

You can use an external tool like Runscope as a webservice proxy to automatically forward requests and pass through responses and view the XML SOAP messages. This is not a native solution on SFDC but it does do the job.

https://www.runscope.com/

0

Using the same WSDL file, try creating a test client e.g. by using Java and Metro.

  • Compare the code generated in Java vs that in your Salesforce org (I've noticed that WSDL2Apex doesn't handle certain parts of WSDLs well, e.g. extensions of other SOAP objects).
  • It should be possible to use the test client to both log and validate the messages coming back from the target system (i.e. test that the structure of the message for the SOAP fault is valid).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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