salesforce-soap-vs-restful-web-services-blog-banner

Exposing Salesforce SOAP vs RESTful Web Services

Exposing Salesforce SOAP vs RESTful Web Services

Exposing a custom Web Service is achieved by writing custom Apex code that will be invoked either using Salesforce 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 Salesforce SOAP and RESTful web services.

Salesforce RESTSalesforce SOAP
REST is not a protocol, it is an architectural  styleSOAP is a protocol
REST uses URL to expose the web serviceSOAP 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 SOAPSOAP requires more bandwidth than REST
RESTful services inherits security measure from underlying  transport layerSOAP 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 implementationSOAP 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 CPUSOAP uses only XML. XML is harder to parse. SOAP uses more memory and CPU
REST is best for social media based ApplicationsSOAP is best for Enterprise web applications, banking transactions…

Let me know if you have any questions about Salesforce SOAP and Salesforce RESTful API! Contact an expert in both Salesforce SOAP and Salesforce RESTful API like ProQuest Consulting today!

salesforce-soap-vs-restful-api

Add a Comment

Your email address will not be published.