3

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

  • Is it necessary to use workbench? Or you want to test the service you have built? – Saroj Bera Jun 10 '16 at 10:48
  • I know how to do that with SOAPUI tool (so I tested my WS with success). But I would like to understand how it could work with Workbench. – Pascal Jun 11 '16 at 13:10
  • check my answer. – Saroj Bera Jun 15 '16 at 4:46
7

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

  • I have the following error message when I try to get the session Id <sf:exceptionCode>INVALID_LOGIN</sf:exceptionCode><sf:exceptionMessage>Login is restricted through MyDomain url only. </sf:exceptionMessage></sf:LoginFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope> – Pascal Jun 16 '16 at 16:41
  • As you said, I have no problem using the enterpise.wsdl to get my sessionId using SOAPUI. When I paste exactly the same request in Workbench, I got this error : Login is restricted through MyDomain url only – Pascal Jun 16 '16 at 16:43
0

Thanks so much for your detailed answer.

I can get the sessionId from SOAPUi or from Developer Console : system.debug(UserInfo.getSessionId()); So this is not a problem.

But I followed your advice for my web service : Method : POST

/services/Soap/class/MyWebService

Request Header : As indicated by Saroj

Request Body : enter image description here

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.