I have generated classes from WSDL file. I'm trying to execute a method from the generated class, there I'm getting the below error.

System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':html'

What can I change to avoid the error?

  • You can try to fix your class according to your endpoint specifications
    – kurunve
    Jul 20 '17 at 15:45
  • 2
    Your server is returning an error page, in HTML. You'll want to use something like SoapUI to diagnose the issue.
    – sfdcfox
    Jul 20 '17 at 15:52
  • @sfdcfox OK,I'll check
    – Rock SFDC
    Jul 20 '17 at 16:15
  • Another option would be to use Assertible (assertible.com) or Postman (getpostman.com) to debug the issues. Both are free to use and similar to SoapUI, but a little more modern (I am a founder at Assertible. Good luck!).
    – creichert
    Jul 20 '17 at 19:40
  • @RockSFDC If you are in a debug org, check for the CALLOUT_REQUEST and CALLOUT_RESPONSE pair in the debug log. You might be able to see the problem response there. Jul 21 '17 at 3:54

This occurs when the external service didn't return a SOAP response. In this case, rather than a SOAP envelope element there is an html element at the start of the response.

As @sfdcfox commented, this indicates the service is returning an HTML response. It's likely some sort of error page, security response, or a redirect.

In a Salesforce Debug org you can check the Apex debug log for the CALLOUT_REQUEST and CALLOUT_RESPONSE pair. The latter should show you exactly what is coming back.

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.