Exposing Salesforce SOAP vs RESTful Web Services

Duygu Johnston

Senior Consultant

May 9, 2018

Exposing Salesforce SOAP vs RESTful Web Services

Exposing a custom Web Service in Salesforce is achieved by writing custom Apex code that will be invoked either using SOAP or REST. Web Services are an abstraction layer allowing systems to communicate independently of their source code language. Java, .Net, PHP, Oracle, ERP systems can communicate with each other through web services over the network without needing to speak each other’s language. When you want to expose a new service, you have to make a decision between 2 standards: SOAP or REST.

SOAP Web Services

SOAP stands for Simple Object Access protocol. SOAP messages are in XML format and sent over HTTP. Defining an Apex method as a SOAP web service is very easy. The method needs to be placed in a global class and must use the keyword ‘webservice’.

global with sharing class MyFirstWebService {
webservice static Case getRecord(String id) {
     // Add custom logic here
}
}

External application can call your SOAP web service by using the class WSDL. WSLD class can be generated by using the WSDL button on the APEX class containing the SOAP web service method. In SOAP, the link between the client and server is not flexible. Any change from both sides would break the linkage.

RESTful Web services

REST stands for Representational State Transfer; REST is an architectural style not a protocol. REST API uses simple HTTP methods using XML or JSON format. You can define your apex classes as REST Resource by defining the class with @RestResource annotation. The URL mapping to access the REST service is defined at the class level too.

You can add @HttpGet annotation to your method so that it can be called by an HTTP get method. Similarly, you can use @HttpDelete, @HttpPatch, @HttpPost, @HttpPut annotations to define your method according to your business needs.

@RestResource(urlMapping='/Cases/*')
global with sharing class CaseService{
@HttpGet
global static Case getCaseById(){
     RestRequest request = RestContext.request;//get the case Id the end
     String cId = request.requestURI.substring(
          request.requestURI.lastIndexOf('/')+1);
     Case result = [SELECT CaseNumber,Subject,Status
                     FROM Case
                     WHERE Id =:cId];
     return result;
}
}

In REST, changes on the client or server would not break the link between them.

Here is the comparison between SOAP and RESTful web services.

REST SOAP
REST is not a protocol, it is an architectural  style SOAP is a protocol
REST uses URL to expose the web service SOAP uses WSDL class to expose the web service
REST allows different data formats: XML, JSON, plain text… SOAP Allows Only XML format
REST requires less bandwidth than SOAP SOAP requires more bandwidth than REST
RESTful services inherits security measure from underlying  transport layer SOAP uses its own security measures. SOAP is based on standardized Web service security. Thus, better secured compared to REST. SOAP is more reliable in terms of security than REST
RESTful service can use SOAP web services as implementation SOAP cannot use RESTful services because SOAP is a protocol.
REST uses JSON. JSON is easier to parse than XML. Thus, REST uses less memory and CPU SOAP uses only XML. XML is harder to parse. SOAP uses more memory and CPU
REST is best for social media based Applications SOAP is best for Enterprise web applications, banking transactions…

 

Let me know if you have any questions!                    

What did you think? Let us know your thoughts!
recent tweets
Need a custom solution?
Drop us a line. We'd love to help.
contact us
ProQuest Consulting is a leading Salesforce partner. ProQuest works to empower companies in Australia and New Zealand to achieve higher performance through the delivery of tailored Salesforce solutions using disciplined Agile Scrum methodology.
Get in touch.

Get social.