I created a Salesforce client using "Generate class from WSDL" feature. When i try to call the web service, throws the following error:

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

  • The request parameter is a String
  • Endpoint: https://www.consorciotransaccional.cl/WSCrm2/CasoPeoplesoftCRMWSService
  • Method to call web service:

    public PageReference LlamarWS()
      crmWsproviderServiceCnsvCl.CasoPeoplesoftCRMWSPort caso =  new  crmWsproviderServiceCnsvCl.CasoPeoplesoftCRMWSPort();
      XMLResponse = caso.saveCasoPeoplesoftCMRPS(Header);
      return null;
  • Variable "Header" is a String containing an XML.

1 Answer 1


The Generate Class from WSDL tool from Salesforce doesn't always fully create a working Apex Class for you to connect to your Web Service with. Personally, I almost always have to fix the generated Apex Class (from the WSDL).

To deduce what variables you need for your classes, you need to see the actual XML response from your Web Service. I suggest using a program like SoapUI to see these request/responses.

Doing this will help you troubleshoot your error -- the error message suggests to me that you are receiving more parameters than you are accounting for hence throwing the error (are you sure you know what parameters you're supposed to get [among all cases -- ex. when you get a "failed" response from your Web Service]).

And in addition to helping troubleshooting this problem, you will need to write Test Code for the Apex Class you just created from your WSDL. To do this, you'll need to create Mock Responses Test Classes where you simulate a response from your Web Service.

For example, I use a Web Service where I have one response for a login (where the WS gives me a SessionID), and then I have another response where I get an Activity File from my WS. And then I also have third response when I try to get an Activity File with an invalid SessionID. So, for this one Web Service, I need 3 Mock Responses Test Classes.

  • This is the response that i get when i try to insert a registry that already exists (Consumed by SOAPUI):<S:Envelope xmlns:S="schemas.xmlsoap.org/soap/envelope"> <S:Body> <ns2:saveCasoPeoplesoftCMRPSResponse xmlns:ns2="crm.wsprovider.service.cnsv.cl"> <return><![CDATA[<docCasoPeoplesoftCrm> <codigoError>131</codigoError> <mensajeError>Ya existe este registro</mensajeError> </docCasoPeoplesoftCrm>]]></return> </ns2:saveCasoPeoplesoftCMRPSResponse> </S:Body> </S:Envelope>
    – Samuel
    Dec 11, 2013 at 13:50
  • Looking at the error you posted, the Parser was expecting S="http://schemas.xmlsoap.org/soap/envelope/" and you actually have S="schemas.xmlsoap.org/soap/envelope/. I think the error/solution lies in setting this correctly. Are you using WebServiceCallout.invoke to perform your SOAP callout? Dec 11, 2013 at 18:57
  • You mean that the parameter (String) i'm passing is no accurate? This is the the Invoke i'm using WebServiceCallout.invoke( this, request_x, response_map_x, new String[]{endpoint_x, '', 'crm.wsprovider.service.cnsv.cl', 'confirmacionCierreCasoCelaPS', 'crm.wsprovider.service.cnsv.cl', 'confirmacionCierreCasoCelaPSResponse', 'crmWsproviderServiceCnsvCl.confirmacionCierreCasoCelaPSResponse'} );
    – Samuel
    Dec 12, 2013 at 13:12
  • it was a hypothesis. hmm did you whitelist your endpoint? (Setup -> Security Controls -> Remote Site Settings) Dec 12, 2013 at 16:03
  • Yes, i have whitelisted -consorciotransaccional.cl
    – Samuel
    Dec 12, 2013 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .