0

This is a broad general question .

We already have a SOAP callout in place where we are hitting the endpoint url after creating the request header and other necessary elements and hitting the method in stub .



Question - How can I make the same callout using HTTP callout ?
How do we send the request xml to the endpoint?

1

You can hand code your own manual XML POST callout using HttpRequest. It will be on you to build up the required XML and then parse the response.


Alternatively, if you have a WSDL to work from, I created an alternative version of WSDL2Apex.

When you import the WSDL you are presented with a list of methods to import. At that stage you can opt to generate the Apex required to perform the HttpRequest.

1

You can use HTTPRequest class to build the request. The actual SOAP message is passed as the body of the request.

    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('https://server-url.com/endpoint);
    request.setMethod('POST');
    request.setHeader('Content-Type', 'text/xml; charset=character encoding');

Now set the request body with SOAP XML String. Here SOAPXML variable contains the actual SOAP XML.

    request.setBody(SOAPXML);
    HttpResponse response = http.send(request);

There are Apex classes to help you build XML: XMLStreamReader class enables you to read XML content and the XMLStreamWriter class enables you to write XML content.

To understand the content type or specify type of content being sent in the HTTP Request this document can help: https://tools.ietf.org/html/rfc3023#page-5

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.