Activity Forums Salesforce® Discussions How to perform soap callout in Salesforce using https?

  • Avnish Yadav

    Member
    July 19, 2018 at 9:27 am

    Hello shraddha,

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

    Here is Example:-

    String s='<soapenv:Envelope xmlns:soapenv="<a target="_blank" href="http://schemas.xmlsoap.org/soap/envelope/"" rel="nofollow">http://schemas.xmlsoap.org/soap/envelope/"</a> ><soapenv:Header>headers here,refer WSDL</soapenv:Header><soapenv:Body> request body.Refer WSDL</soapenv:Body></soapenv:Envelope>';
    HttpRequest req = new HttpRequest();
    req.setEndpoint('the URL from service provider');
    req.setMethod('POST');
    req.setBody(s);
    req.setHeader('Content-Type', 'text/xml');
    req.setHeader('SOAPAction', '""');
    Http http = new Http();
    HTTPResponse res = http.send(req);
    System.debug('Saraag-Here is your response:'+res.getBody());

    Thanks.

  • shariq

    Member
    September 19, 2018 at 1:48 am

    Hi,

    Use WSDL2Apex to Generate Apex Code
    In addition to REST callouts, Apex can also make callouts to SOAP web services using XML. Working with SOAP can be a painful (but necessary) experience. Fortunately, we have tools to make the process easier.
    WSDL2Apex automatically generates Apex classes from a WSDL document. You download the web service’s WSDL file, and then you upload the WSDL and WSDL2Apex generates the Apex classes for you. The Apex classes construct the SOAP XML, transmit the data, and parse the response XML into Apex objects. Instead of developing the logic to construct and parse the XML of the web service messages, let the Apex classes generated by WSDL2Apex internally handle all that overhead. If you are familiar with WSDL2Java or with importing a WSDL as a Web Reference in .NET, this functionality is similar to WSDL2Apex

    Generate an Apex Class from the WSDL

    • From Setup, enter Apex Classes in the Quick Find box, then click Apex Classes.
    • Click Generate from WSDL.
    • Click Choose File and select the downloaded calculator.xml file.
    • Click Parse WSDL. The application generates a default class name for each namespace in the WSDL document and reports any errors.For this example, use the default class name. However, in real life it is highly recommended that you change the default names to make them easier to work with and make your code more intuitive.

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos