Thursday 20 December 2018

What is Web services and what they do.? Types of Web services.?


Web service is a standardized medium to propagate (transmit or spread) communication between the client and server applications on the World Wide Web.

A web service is a software module which is designed to perform a certain set of tasks.
The web services can be searched for over the network and can also be invoked accordingly.
When invoked the web service would be able to provide functionality to the client which invokes that web service.
Web Services Revealed

Web services are part of the Services Oriented Architecture. Web services are used as the model for process decomposition and assembly. I have been involved in discussion where there were some misconception between WEB SERVICES and WEB API.

The W3C defines a Web Service generally as:
1. A WEB SERVICES is a software system designed to support interoperability machine-to-machine interaction over a network.
2. Web API also known as Server-Side Web API is a programmatic interface to a defined request-response message system, typically expressed in JSON or XML, which is exposed via the web – most commonly by means of an HTTP-based web server.


Question
When to use SOAP and when to use REST?

1. Rest is based on http protocol (get, put, post, delete) , treating everything as a resource, whereas SOAP is transport agnostic
2. Soap works only with xml, Rest works with json/xml both.
3. Rest do not provide schema definition when implemented as JSON, Soap will always provide schema definitions.
4. It will be easy to understand request/response schema and their data type constraints when viewing schema information via WSDL by any client.
5. The step of wsdl creation makes it difficult to make any changes in your schema classes while implementing in soap. Rest implementation is quite easy; we just need to make changes in pojo classes.
6. Soap provides default error handling via faults. We can also create our own custom faults.
7. In Rest we need to handle all error messages explicitly.
8. Soap provides SoapHandler to intercept request both at client/server side with both request/response. We can use filters of j2ee or interceptors of Spring to intercept calls.
9. Soap is fixed defined set of protocol, whereas rest is architectural style. While implementing REST, developers can follow any rule,

For example
Not using http protocol in well-defined way. While in Soap message part is defined as envelope.
One envelope=header+body+fault+attachment

Use REST for

1. Totally stateless operations: If you need stateless CRUD (Create, Read, Update, and Delete) operations, then REST is it
2. Caching situations: if the information can be cached because of the totally stateless operation
3. Limited bandwidth: SOAP XML response consumes more bandwidth compared to REST response


Use SOAP for

1. Asynchronous processing and invocation: if your application needs a guaranteed level of reliability and security
2. Formal contracts: if both sides (provider and consumer) have to agree on the exchange format
3. Stateful operations: if the application needs contextual information and conversational state management

Remember
HTTP binding uses Verbs (Get, Post i.e. Retrieve/Reading, Insert/Writing). 
REST binding uses HTTP Verbs (Get, Put, Post, and Delete Method i.e. Retrieve/Reading, Update/Editing, Insert/Writing, Delete/Removing). 

No comments:

Post a Comment