function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
clouddev@surashriclouddev@surashri 

Apex Methods as SOAP Web Services

Hi,

 

I am currently reading on "Apex Methods as SOAP Web Services". After reading apex documents and material on net. I could manage to gather logical steps given below to use apex method as SOAP web service.

 

  1. Write a public class and a static webservice(keyword) method. This will be exposed as web service method because of webservice keyword.
  2. Generate a WSDL file for above class.
  3. Also generate Enterprise WSDL file(??) I am not sure the exact use of this file.
  4. Consume both files in any of the languages like C#, .NET, PHP etc.
  5. This will generate appropriate code in one of these languages.
  6. Write a code with username,password authentication to call webservice method written in step 1.(??) Are there a standard steps available to call this method (Similar to SQL cursor)?
  7. Run Test to check correct results.

Can someone please correct me if I am wrong in putting above steps? Also explain why we need this enterprise WSDL and query asked in Step 6?

 

If some one can send a working example to try, It will help a lot.

 

Thanks,

 

clouddev

 

Best Answer chosen by Admin (Salesforce Developers) 
clouddev@surashriclouddev@surashri

Thanks to all for your valuable contribution.

 

clouddev

All Answers

SharathChandraSharathChandra

For authentication we use login operation which is present in enterprise wsdl.

We know that WSDL consists of <portType> element which will have all the operations you can perform.

 

clouddev@surashriclouddev@surashri

Hi Cherrlin,

 

Could you please confirm the steps I mentioned are logical? Also reply to my other questions.

 

Thanks for your reply,

 

clouddev.

sfdcfoxsfdcfox

In regards to step 3, you have to use sforce.login() to actually log in to salesforce before you can consume a web service function. This is why you need the Enterprise WSDL file. In any given language, the steps will look something like this:

 

Sforce client = new Sforce();
LoginResult login = client.login(username,password);
if(login.sessionId) {
  MyWebService ws = new MyWebService();
  ws.setSessionId(login.sessionId);
  MyWebServiceResult result = ws.doAction(params);
}

Note that I'm not including any specific error handling or so on, as this is only to illustrate the general steps. In the example above, Sforce is the class introduced by the Enterprise WSDL, and MyWebService is the class introduced by your Apex Code's WSDL. You will need to refer to your development environment's specific resources (e.g. the Solution or Project tree) to see which functions are available to you, and the proper names to use for the client functions.

clouddev@surashriclouddev@surashri

Thanks to all for your valuable contribution.

 

clouddev

This was selected as the best answer