[SalesForce] Salesforce SOAP Exception – Expecting Envelop found Fault

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!

Best Answer

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.

Related Topic