[SalesForce] How to consume a soap web service using workbench

I would like to call a SOAP web service created in salesforce, using Workbench. There are some samples for other types of web services from the apex workbook but not for SOAP 🙁

My class contains 2 methods, each one containing an argument.
Here is my code :


global class WsMyWebServiceClass {

...

webservice static List<Account>  getAccount(Integer  days) {
_________________________

How can I test my method from Workbench ?

When I log in Workbench, I select Utilities | Rest Explorer

Get is selected by default

/services/data/v36.0 is prefilled

If I type /services/Soap/class/WsMyWebServiceClass and click on Execute, I get the following message :

GET not supported, this is a SOAP service, please use POST

So when I switch to Post, there is a Request Body that appears and I don't know what to fill in it ? Some JSON ?

When do I indicate that I'm using the getAccount method ?

If I use Post method, what do I need to fill for the 2 fields ?

/services/Soap/class/WsMyWebServiceClass… ?????
Request body ?

enter image description here

Best Answer

Here is how I have tried using workbench to test a SOAP web service. Hope this helps.

First you have to get the session ID by passing a Soap request(I copied the request XML from SoapUI) to login method of the Salesforce SOAP API.

Service URL: /services/Soap/u/37.0

Method : Post

Request Headers: (below)

Content-Type: text/xml; charset=UTF-8
Accept: text/xml
SOAPAction: ''

Soap Request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
   <soapenv:Header>
      <urn:CallOptions>
         <urn:client></urn:client>
         <urn:defaultNamespace></urn:defaultNamespace>
      </urn:CallOptions>
      <urn:LoginScopeHeader>
         <urn:organizationId></urn:organizationId>
         <!--Optional:-->
         <urn:portalId></urn:portalId>
      </urn:LoginScopeHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>****************</urn:username>
         <urn:password>****password+security token****</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

Execute it you will get the webservice response.

In the response you will get the session ID. Copy it and keep it in your notepad to call your Apex webservice.

enter image description here

For next call you have to use the following details.

Service URL: /services/Soap/class/sarojkbera/MyWebService (MyWebService is the Apex class exposed as Soap service)

Apex Class:

global class MyWebService {
    webService static String makeContact(String firstName, String lastName) {
        return 'Hello '+firstName+' ' +lastName;
    }
}

Method : Post

Request Headers: (below)

Content-Type: text/xml; charset=UTF-8
Accept: text/xml
SOAPAction: ''

Soap Request:

Here I have used the generated Soap request from SoapUI.

Put the session ID (obtained in the previous step) in the request XML.

Execute it and you will get the Webservice response as below.

enter image description here

Related Topic