Find your content:

Search form

You are here

How to make a SOAP call using APEX Class?

 
Share

I have to connect to an external application for which I'm provided with "usernames, passwords, token id, host url". This host url is a WSDL one which ends with "..sample.php?wsdl" and upon running it in the browser, it lists out the methods it has got. Till these days, I was using RESTful services to connect to that application.

Now, I would like to know how to invoke those "methods" from WSDL link and get the needed response from them.


Attribution to: Sapthagiri

Possible Suggestion/Solution #1

If your WSDL is proving to be problematic with the built in wsdl2apex implementation that Salesforce provides you could also try the version they make available via GitHub.

Another alternative is the version created by FuseIT (Disclosure, this is my current employer - FuseIT SFDC Explorer. This is a free tool that provides some more flexibility than the built in wsdl2apex. For instance, it can import external service descriptions and ignore/skip unsupported elements so you can still access parts of the web service.

See also:


Attribution to: Daniel Ballinger

Possible Suggestion/Solution #2

As in other programming languages, you can generate Apex code starting from the WSDL using the "Generate from WSDL" button present at the top of the Apex Classes list in the Setup UI. The process is described e.g. in SOAP Services: Defining a Class from a WSDL Document.

However, there are a number of limitations in that tooling, including that it only supports SOAP 1.1. Some of these can be worked around by editing a copy of the WSDL before the Apex code is generated (very commonly needed) and others by editing the generated Apex code. Googling will return a number of postings on that subject e.g. Getting Apex2wsdl parse External application WSDLs and make it work.

The most extreme work-around is to manually write Apex code that generates the request XML, makes the HTTP calls and parses the response XML: the WSDL contains all the necessary specification to be able to do that (but WSDL and the XML Schema that is part of it are not simple things). That is a lot of work and not easy to get right.

So the overall approach is to get the WSDL file, and start by using "Generate from WSDL" and deal with the problems that come up. You could be lucky and experience few or no problems...

(You will have to wire up e.g. a button to a controller to test calls against the real external service as such calls can't be made from an Apex unit test: only calls to a mock can be made from unit tests.)


Attribution to: Keith C
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34644

My Block Status

My Block Content