When to use SOAP over REST Web Service. Is REST better than SOAP?

When to use SOAP over REST Web Service.
Is REST service better than SOAP service?
Difference between SOAP and REST Web Service. OR
SOAP Vs REST Web Service.


When to use SOAP over REST Web Service. Is REST service better than SOAP service. Benefits of SOAP over REST service. 

Let's see, important difference between SOAP and REST Service which will help you decide which to choose among both.



No SOAP REST
1 SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer.
2 SOAP is a protocol, which says how client and server
will communicate that is the way they will exchange information.
REST is a software architectural style (concept) as how the system should be designed to solve common occurring problems in many applications.

Even though an architectural pattern conveys an image of a system, it is not an architecture.

REST is simply a concept and protocol for exchanging information is up to implementer.
3 SOAP protocol uses XML as a medium for exchanging information between client and server. REST keeps it open to implementer as what protocol they want to use.

Protocol here is not fixed, Implementer can use XML, JSON Plain text, HTML etc as a medium for exchanging information between client and server.


4 One of the most important point is, SOAP uses services interfaces to expose the business logic.

@WebService
 interface WeatherService{

   @WebMethod  
   public String getWeather(String  
   cityName);
 
}

In SOAP, we expose the above WeatherService interface and operation inside it. For above sample service, getWeather() method is exposed to outside world which take city name as input and return weather details as output.
In REST, intsead of Service interface, URI are exposed to outside world.

@Path("/WeatherService")
class WeatherService{

    @Path("/GetWeather/{cityName}
    public String getWeather(
         @PathParam("cityName") String
         cityName){
        ....
    }
}

So the URI to invoke above method will be:

http://<AppName>:/WeatherService/GetWeather/

5 SOAP defines much standards that need to strictly followed for communication.

Eg: Any exceptions in communication from service should go in Fault section.
REST does not define too much standards like SOAP and implementer can have there own way of implementing things.
6 SOAP requires more bandwidth and resource than REST because Payload created in XML is large in size. REST generally uses JSON due to which it requires less bandwidth and resource compared to SOAP.

Payload created in JSON is not as large compared to XML.
7 SOAP defines its own security by using WS-Security extensions.

SOAP calls can be secure with HTTP SSL encryption & WS-Security encryption for its SOAP messages.
RESTful web services inherits security measures from the underlying transport layer used.

REST calls can be secure only with HTTP SSL encryption.
8 SOAP uses WSDL(Web Services Description Language) for describing the functionality offered by a web service. REST uses WADL(Web Application Description Language) for describing the functionality offered by a web service.
9 SOAP has built-in Error handling features. So if there is problem with the SOAP request sent, SOAP response will contain error information of it.

In case of REST there is no standard in built error handling feature provided and developer need to handle by passing custom response codes.
10 SOAP messages can be sent not only over HTTP protocol but also with SMTP and other protocols that is SOAP is Language, platform, and transport independent

REST requires use of HTTP.
11 SOAP uses XML for exchanging information and parsing of XML is complex compared to JSON and require explicit parsers for handling it.

REST uses JSON for exchanging information and biggest advantage of JSON is its in-built support with JavaScript and the browser, making the API consuming and parsing lot more easy.
12 Avoid the use of SOAP in situations where bandwidth is very limited.
Example: In case of Mobile client consuming the services.

Make use of REST services where bandwidth and resource is constraint as JSON is more lightweight compared to XML.
13 The disadvantage of SOAP is. If say you already have JSON, CSV parsers in your application and your need is to consume SOAP web services than it is compulsory for you to include/write XML parser because you cannot use JSON, CSV parsers already exist in your project.

Biggest advantage of REST is. If say you already have CSV parser in your application and your need is to consume REST web services than REST service has ability to send response in not only JSON format but it is free to send response in the format client understands.
14 SOAP is standardized and contains pre-build extensibility in the form of the WS* extensions. For enterprise applications SOAP is more preferred because of security it provides. REST is not standardized and is becoming popular day by day. REST is generally less preferred where security is biggest concern like banking applications.
15 SOAP services are not cacheable as there is a need to explicitly form a SOAP request so that server can understand.


Say if you like to purchase any mobile and want to share details of that mobile with your friend in this case you need to explicitly tell your friend to go to xyz url and then press this button etc. which is painful.

REST services are cacheable.

This feature is very useful, Say if you want to share with your friend a Mobile details that you are planning to purchase, what you need to do is just share the link which is a REST call.
16 SOAP request are send using HTTP POST method only because SOAP request formed is usually big and cannot be send in Query string and that is why SOAP request cannot be bookmarked.

(It says SOAP request can use HTTP GET method as well.
I have not came across till now any SOAP request passed using HTTP GET method)

REST request are send using both HTTP GET and POST request due to which GET request can be cached here.
17 SOAP requires learning and ultimately takes time. With REST, learning curve is less and one can easily produce and consume services.
18 SOAP WSDL file can be extracted from endpoint in the way shown below.

{Service_Endpoint}?WSDL
REST WADL file can be extracted from endpoint in the way shown below,

http://{ip}:{port}/{AppName}/{web.xml mapping to REST container}/application.wadl


Please comment if you feel any point is missed or any point mentioned is incorrect.



Enjoy !!!! 

If you find any issue in post or face any error while implementing, Please comment.

Post a Comment