Creating SOAP Web Service in Apex

Posted on 14-02-2013 16:02 by graham
This tutorial shows how to create and expose a Web Service in Salesforce Apex.

Creating a service


Creating Web Services in Apex is achieved by using the keyword webservice on a method that we want to expose as a service.
MathOperations.cls
global class MathOperations
{
webservice static Integer getSum (Integer a, Integer b)
{
return a + b;
}
}

This looks simple, huh? And it is. One thing you need to remember about is to make the class containing the service method global - it is Salesforce's requirement that all classes containing Web Service methods be global.

Exposing the service with WSDL


If we want to make our Web Service available to any other party, they will have to have the WSDL file containing the service's definition.

To obtain the WSDL file, go to Setup | App Setup | Develop | Apex Classes, find the class containing your Web Service, and click the "Generate WSDL" button that should be found on top of the class screen.
Comments

 

Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
Email:
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems