Print this page

System.CalloutException: Web service callout failed: Failed to get next element - Multipart responses are not supported

Knowledge Article Number 000213912
Description I am performing a web service callout but the debug logs show the exception "Web service callout failed: Failed to get next element". Why is this happening? The body contains a valid XML document that is complaint with the schema that was imported into Salesforce.

11:12:06.213 (1213388226)|CALLOUT_RESPONSE|[111]|
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml";
Content-Transfer-Encoding: binary
Content-ID: <>

<soap:Envelope xmlns:soap=""><soap:Body>...</soap:Body></soap:Envelope>
11:12:06.213 (1213814277)|EXCEPTION_THROWN|[111]|System.CalloutException: Web service callout failed: Failed to get next element
Resolution On receiving a response from the external web service, Salesforce will attempt to parse it and serialize into the Apex classes that were generated using the provided web service's WSDL. The expectation is that the body of the response is a valid XML document, as the parser will expect a <soap:Envelope> element to be the first XML node present in the response after the prolog (if present). However when there are non-XML elements in the response preceding the <soap:Envelope> element, the parser will throw the exception "Failed to get next element".

In the above scenario, the response's format is that of a multipart response where you may notice --id in the first line, and --id-- in the last line which delimit the first and only part of this multipart response. On attempting to parse this response, the parser encounters --id and fails as it does not expect this non XML element or the response headers on subsequent lines. In summary, at present the parser does not support multipart responses, so it is suggested that the web service is modified to not send multipart responses.

promote demote