1

I am referring this trailhead unit which has below text-

Apex callouts come in two flavors.

  • Web service callouts to SOAP web services use XML, and typically require a WSDL document for code generation.
  • HTTP callouts to services typically use REST with JSON.

These two types of callouts are similar in terms of sending a request to a service and receiving a response. But while WSDL-based callouts apply to SOAP Web services, HTTP callouts can be used with any HTTP service, either SOAP or REST.

How can we call SOAP webservice using HTTP callout. Is it an error on trailhead.

5

SOAP is a specialization of REST. In other words, a programming language or tool that only understands REST can be coerced into calling a SOAP endpoint, but a tool that only understands SOAP cannot call any REST endpoint, only those that follow the SOAP rules.

Without SOAP support, it simply means that the developer must be willing to use other tools to build the proper XML payload that is defined by SOAP. There are no examples of calling a SOAP-based service via REST techniques, because that would largely be duplicating the documentation for calling any REST-based service, and then having to explain how to build a SOAP payload manually.

SOAP is relatively difficult to get right, compared to simple formats like YML or JSON, as it has different versions (1.0, 1.1, 1.2), different "modes" (RPC/Literal, Document/Literal, RPC/Encoded, and Document/Encoded), and so on. An example written would only give you a small slice of the SOAP pie, or would be so large, it would no longer be an example, but a full-fledged outing.

To put it in perspective, this is what an example of calling SOAP via REST looks like:

String action = getSoapAction(), 
       endpoint = getSoapEndpoint(), 
       soapBody = getSoapBody();
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setHeader('SOAPAction', '"'+action+'"');
req.setBody(soapBody);
HttpResponse res = new http().send(req);
Dom.Document responseXml = new Dom.Document();
responseXml.load(res.getBody());
processResponse(responseXml);

You see the bits I left out? Those are the pieces you need to fill in as a developer.

Was this example interesting? Not really. It's basically exactly the same as what you'd do for any REST call, just with a couple of extra bits thrown in. There's absolutely nothing special about this that calls for it to have its own section in the documentation.

The bits that are left out are complicated and service dependent. Anything I could write there would work for one specific service, and nothing else. It would be a waste of time for me to write such code. If you're interested in learning more, you can read the specs over at w3c, or you could use a tool like SoapUI to see what the payload should look like based on a given WSDL. Other than that, it's all just minutiae, tiny details you have to get just right.

1

HTTP callouts can be made to SOAP based service or REST based service. While making callout to REST based service, you would set the request header content-type as application/json and pass the stringified JSON as request body. In case of callout to SOAP based service, you would set the request header content-type as text/xml and pass the SOAP envelope string as request body.

HTTP callout to REST service is generally easier to call and then parse the response, which makes it preferable over SOAP based service.

1
  • can you please provide any documentation link from salesforce. I could only see Http callout for Rest in salesforce docs. XML is very well supported by Rest services and Apex natively supports json and XML both for rest HTTP callouts.
    – love gupta
    Apr 26 '20 at 16:35

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.