There are several posts about the Soap vs Restfull type of webservices.I worked on both types of webservices, here are my point of view on SOAP vs REST.
SOAP stands for “Simple Object Access Protocol”. REST stands for “Representational State Transfer”.
Simplicity - SOAP is XML based messaging protocol while REST is not a protocol but its an architectural style.SOAP has a standard specification while REST lacks in this area.There is no internal mechanism of converting your object to an XML( or Jason) , you have to write code for that,therefore RESTfull webservices are simple to develop if we have a simple requirement something like returning the marital status of a person(a simple string married or un-married etc.) but for complex webservices SOAP is simple to develop as we don’t need any code for flattening our object into XML or vice-versa. SOAP uses interfaces and named operations to expose business logic while REST uses URI and HTTP methods like (GET, PUT, POST, DELETE) to expose resources.Therefore SOAP is more understandable than REST. For service that changes frequently and are complex in nature, SOAP is a better option.
Performance – RESTfull web services are much faster with compare to SOAP as REST has less intermediatory operations to do with compare to SOAP. Response of RESTFull web services can be cached at the client side.
Security – SOAP based webservices are more secure then RESTfull webservices. WS-Security is the specification for security in the SOAP based Webservices. WS-Security provides detailed standard rules for security in the SOAP based webservices . Like this we have separate specifications for transactions, messaging, etc in SOAP. While REST does not provide any standard specification for such functionalities.The only security measures can be used with REST is secure data transfer by using HTTPS(SOAP also can be used on HTTPS).
Validity- SOAP based webservices has a SOAP schema for every part of implementation and strongly types, while REST doesn’t has any schema(you have to validate the incoming/outgoing messages by your own). SOAP has a Formal contract between the client and the webservice(through wsdl), while REST doesn’t has such kind of contract.
Flexibility- SOAP supports various protocols like HTTP, SMTP, JMS etc, while REST only supports HTTP. SOAP only supports XML format of data transfer while REST can support XML and JSON as well(JSON data may be very smaller in size with compare to XML), its upto you to decide which is better in this area,its totally domain/requirement driven decision.
Ajax Support- One major benefit for REST may be that its totally based on HTTP protocol so an XMLHttpRequest (Ajax Call) can be made using REST. While SOAP doesn’t has this feature.Therefore REST wins in this area.
Scalability- SOAP services are much harder to scale than RESTful services, because REST webservices are fast and consume lack resources.
Statefull Support - If the application needs to maintain the states between the conversations state then SOAP has the additional specification to support those things (Security, Transactions, Coordination, etc). But in the REST approach developer has to implement these features by adding his/her own code.Its better to use REST if you have stateless operations to perform(Like CRUD operations), its better to use SOAP for the operations where there is a need of maintaining the conversational state.
Inter-opearability in Distributed Environment – SOAP provides support for distributed transaction management while REST doesn’t provides such support. Therefore for a distributed environment SOAP is a better choice, REST is mainly for Client-Server kind of environment.
When to use REST
- If there is limited bandwidth and resources.
- If operations are totally stateless.
- If information can be cached because of stateless nature of resources.
- If there is limited bandwidth and resources.
- If operations are totally stateless.
- If information can be cached because of stateless nature of resources.
When to use SOAP:
- If application needs a guaranteed level of reliability and security.
- If both provider and consumer have to agree to an exchange format.
- If application needs a guaranteed level of reliability and security.
- If both provider and consumer have to agree to an exchange format.
I think RESTFull webservices are for internet facing applications and SOAP is for enterprise applications.
Now you know when to use what.
No comments:
Post a Comment