Sunday, November 15, 2015

Difference between SOAP and RESTful Web Service in Java

Though both SOAP and RESTful web services allows a client to query server for some information, but the way they are implemented and used is quite different. Main difference between SOAP and REST is that former provides an standard of communication between client, server and other parties and has restricted set of rules and format, while REST leverages ubiquity of HTTP protocol, in both client and servers, to allow them to communicate with each other regardless of their implementation. In short, getting data from a RESTful web service requires less headache then getting data from a SOAP web service. Since everybody is familiar with HTTP requests like GET or POST, its easy to understand and correlated how RESTful webservice are working and which URL of REST web service provides what kind of information. In SOAP, you need to understand lengthy WSDL document to find out right methods and right way to call them.

 Difference between REST and SOAP in Java

Here are some fundamental differences between REST, RESTful and SOAP Web Services, which will help you not only to understand these two key technologies better but also to answer some tricky Java web services questions based upon these two technologies :

Short Form
REST stands for REpresntational State Transfer (REST) while SOAP Stands for Simple Object Access Protocol (SOAP).

Architecture style vs Protocol
REST is an architectural style, on which RESTFul web services are built, while SOAP is a standard devised to streamline communication between client and server in terms of format, structure and method.

Use of HTTP Protocol
REST takes full advantage of HTTP protocol, including methods e.g. GET, POST, PUT, and DELETE to represent action e.g. from an application which provides data related to books, GET request can be used to retrieve books, POST can be used to upload data of a new book, and DELETE can be used to remove a book from library. On the other hand SOAP uses XML messages to communicate with server.

Supported Format
RESTful web service can return response in various format e.g. JSON, XML and HTML, while by using SOAP web service you tie your response with XML because actual response is bundled inside a SOAP message which is always in XML format.

Speed
Processing a RESTful web service request is much faster than processing a SOAP message because you need to less parsing. Because of this reason RESTful web services are faster than SOAP web service.

Bandwidth
SOAP messages consumes more bandwidth than RESTFul messages for same type of operation because XML is more verbose than JSON, standard way to send RESTFul messages and SOAP has additional header for every message, while RESTFul services utilizes HTTP header.

Transport Independence
Since SOAP messages are wrapped inside a SOAP envelop it can be sent over to any transport mechanism e.g. TCP, FTP, SMTP or any other protocol. On the other hand RESTful web services are heavily dependent upon HTTP protocol. They used HTTP commands their operation and depends upon on HTTP for transmitting content to server. Though in real world, SOAP is mostly over HTTP so this advantage of transport independence is not really utilized.

Resource Identification
RESTful web services utilizes URL to identify the desired resources to be accessed, while SOAP uses XML messages to identify the desired web procedure or resource to be invoked.

Security
Security in RESTful web service can be implemented using standard and traditional solutions for authorized access to certain web resources. While to implement security in SOAP based web services you need additional infrastructure in web to enable message or transport level security concerns.

Caching
RESTful web service take full advantage of web caching mechanism because they are basically URL based. On the other hand, SOAP web services totally ignore web caching mechanism.

Approach
In REST based web-services every entity is centered around resources, while in case of SOAP web service, every entity is centered around interfaces and messages.

Read More 

Java 7 features
How to Reset Arraylist In Java
How HashMap Work in Java
Why wait (), notify () and notifyAll () must be called from synchronized block or method in Java
XPath to locate Information in XML
Internals of Garbage Collector
Reference Type in Java
Different Ways to Create ObjectClass Loaders in Java
Producer Consumer Problem
Why String is Final in Java
Singleton Class using Enum
JSON tutorial
 Exceptional Handling in Java

No comments:

Post a Comment