function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pinoytechiepinoytechie 

WebServiceCallout (wsdl2apex)

good day!

We have a system that consumes webservice in SAP. Due to the complexity of webservice structure that SF is invoking in SAP, we use the tool wsdl2apex to generate stub classes. Basically, the connectivity is like this:
SF ==> APIgee ==> Siteminder ==> SAP

The system needs a few enhancements particularly in logging. To goal is to have comprehensive log, to easily pinpoint the culprit when failure happens. The main reason why this enhancement conceived is that there were some webservice/network/middleware-related issues and we really had a hard time tracing that.

When we had those issues, the log only says:
Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
The error message above is same error when we had authentication error, gateway timeout, SAP unavailability, or any siteminder error, which is being relayed to APIgee, the point where SF connects. The errors actually would have different HTTP headers and messages in the body, but I don't know how to get the content/body and headers using wsdl2apex (or WebServiceCallout) approach.

QUESTIONS:
  1. How do I extract/generate the XML SOAP envelope being sent to webservice from the stub classes generated by wsdl2apex?
  2. How do I extract/generate the raw data returned by the webservice from the stub classes generated by wsdl2apex?
  3. How do I get the HTTP headers returned by the webservice from the stub classes generated by wsdl2apex?

NOTE: when the call was a success, outputHttpHeaders_x contains HTTP headers. However, when there's an error, i.e. 400, 401, 404, 40x, outputHttpHeaders_x is not getting populated. Though a SOAPUI simulation clearly shows there were headers returned.

Please don't tell me to use HTTPRequest instead. I am not in the position to revamp the current code, and I don't have the time and budget to do that. Also, we have a very complex webservice and wsdl2apex tools is really handy to generate all the stubs for such complex webservice.

THANK YOU!
James LoghryJames Loghry
I've done my fair share of wsdl -> apex integrations, and really there is no good way of handling when the web service returns an HTTP response vs. an XML response, such as with an authentication failure which is what you're encountering.

I think at this point your best bet is to either assume that the HTML response means an authentication failure and handle it accordingly, try wrapping the apigee service with exception handling and return an XML response instead if possible, or unfortunately rewrite your callout to remove the wsdl 2 apex dependency, although I know that's not what you wanted to hear.