+ Start a Discussion
Aldrin Rasdas 26Aldrin Rasdas 26 

System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found 'urn:sap-com:document:sap:soap:functions:mc-style:...'

Hi,

I'm trying to consume/call a webservice from SAP/APIGEE. I have already the target endpoint to remotes sites settings, etc.

Given the WSDL file from SAP/APIGEE team, I have generated the stub class using "Generate from WSDL"

But when trying to call the service, i am getting this error:
System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found 'urn:sap-com:document:sap:soap:functions:mc-style:GetEmployeeResponse'

Here's the WebServiceCallout.invoke lines (if it matters: i can see that the expected response is correctly specified, and yet it looks for something else)
WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'urn:sap-com:document:sap:soap:functions:mc-style',
              'GetEmployee',
              'urn:sap-com:document:sap:soap:functions:mc-style',
              'GetEmployeeResponse',
              'HLG_sapComDocumentSapSoapFunctionsMcS.GetEmployeeResponse_element'}
            );

I tried to simulate the call using SOAPui, and the result/response is something like this:
<ns1:GetEmployeeResponse xmlns:ns1="urn:sap-com:document:sap:soap:functions:mc-style">
   <Empinfo>
      <EmployeePersonalNumber>10033928</EmployeePersonalNumber>
      <UserName>abhyrtj</UserName>
      <AssignmentType>AB</AssignmentType>
      <AssignmentTypeDescription>test description</AssignmentTypeDescription>
      <CompanyCode>CC</CompanyCode>
      <CmapnyName>Test Company</CmapnyName>
      <Ctps>test</Ctps>
      <CtpsSerie>test</CtpsSerie>
      <CtpsUF>test</CtpsUF>
      <Imss>test</Imss>
      <Nationality>US</Nationality>
      <CountryName>USA</CountryName>
      <AnnualSalary>435345.02</AnnualSalary>
      <AnnualSalaryCurrency>$</AnnualSalaryCurrency>
      <AnnualCurrencyDescription>test description</AnnualCurrencyDescription>
      <WorkContract>AB</WorkContract>
      <WorkContractDescription>test description</WorkContractDescription>
      <EndDate>2017-12-25</EndDate>
      <EmploymentPercentage>98.25</EmploymentPercentage>
      <HoursPerWeek>9.00</HoursPerWeek>
   </Empinfo>
</ns1:GetEmployeeResponse>

THANK YOU SO MUCH IN ADVANCE!
kiranmutturukiranmutturu
Check https://help.salesforce.com/apex/HTViewSolution?urlname=Web-service-callout-failed-Unexpected-element-Parser-was-expecting-element-http-schemas-xmlsoap-org-soap-envelope-Envelope-but-found-HTML&language=en_US (https://help.salesforce.com/apex/HTViewSolution?urlname=Web-service-callout-failed-Unexpected-element-Parser-was-expecting-element-http-schemas-xmlsoap-org-soap-envelope-Envelope-but-found-HTML&language=en_US)

This may help you to trace the issue
Aldrin Rasdas 18Aldrin Rasdas 18
(I am the thread starter... just can't remember which account i used to do the first post)

Hi kiran. Thanks for the link. However, none of signs stated in the link is true in my situation. In my situation, it has no connection problem whatsoever... and the endpoint is returning what it needs to throw back.

As per salesforce log (developer console), it's getting the same XML as retrieved by SOAPUI:
15:54:01:636 CALLOUT_RESPONSE [110]|<ns1:GetEmployeeResponse xmlns:ns1="urn:sap-com:document:sap:soap:functions:mc-style"><Empinfo><EmployeePersonalNumber>10033928</EmployeePersonalNumber><UserName>abhyrtj</UserName><AssignmentType>AB</AssignmentType><AssignmentTypeDescription>test description</AssignmentTypeDescription><CompanyCode>CC</CompanyCode><CmapnyName>Test Company</CmapnyName><Ctps>test</Ctps><CtpsSerie>test</CtpsSerie><CtpsUF>test</CtpsUF><Imss>test</Imss><Nationality>US</Nationality><CountryName>USA</CountryName><AnnualSalary>435345.02</AnnualSalary><AnnualSalaryCurrency>$</AnnualSalaryCurrency><AnnualCurrencyDescription>test description</AnnualCurrencyDescription><WorkContract>AB</WorkContract><WorkContractDescription>test description</WorkContractDescription><EndDate>2017-12-25</EndDate><EmploymentPercentage>98.25</EmploymentPercentage><HoursPerWeek>9.00</HoursPerWeek>  </Empinfo></ns1:GetEmployeeResponse>
Let me just reformat what was in Salesforce CALLOUT_RESPONSE:
15:54:01:636 CALLOUT_RESPONSE [110]|

<ns1:GetEmployeeResponse xmlns:ns1="urn:sap-com:document:sap:soap:functions:mc-style">
	<Empinfo>
		<EmployeePersonalNumber>10033928</EmployeePersonalNumber>
		<UserName>abhyrtj</UserName>
		<AssignmentType>AB</AssignmentType>
		<AssignmentTypeDescription>test description</AssignmentTypeDescription>
		<CompanyCode>CC</CompanyCode>
		<CmapnyName>Test Company</CmapnyName>
		<Ctps>test</Ctps>
		<CtpsSerie>test</CtpsSerie>
		<CtpsUF>test</CtpsUF>
		<Imss>test</Imss>
		<Nationality>US</Nationality>
		<CountryName>USA</CountryName>
		<AnnualSalary>435345.02</AnnualSalary>
		<AnnualSalaryCurrency>$</AnnualSalaryCurrency>
		<AnnualCurrencyDescription>test description</AnnualCurrencyDescription>
		<WorkContract>AB</WorkContract>
		<WorkContractDescription>test description</WorkContractDescription>
		<EndDate>2017-12-25</EndDate>
		<EmploymentPercentage>98.25</EmploymentPercentage>
		<HoursPerWeek>9.00</HoursPerWeek>
	</Empinfo>
</ns1:GetEmployeeResponse>

So it is clear that the service is giving out what it needs to give... and yet apex is giving out error.

Badly needs help...