Thursday 16 January 2020

Web Services

Web services are web based applications.It is a collection of standards or protocols for exchanging information between two devices or application.
The Web Service is a standard software system used for communication between two devices (client and server) over the network. Web services provide a common platform for various applications written in different languages to communicate with each other over the network.

Web services are the types of internet software that uses standardized messaging protocol over the distributed environment. It integrates the web-based application using the REST, SOAP, WSDL, and UDDI over the network.


There are mainly two types of web services.
1. SOAP web services.
2. RESTful web services.

These are some of the important advantages of web services:

Interoperability: With the help of web services, an application can communicate with other application developed in any language.
Reusability: We can expose the web service so that other applications can use it.
Modularity: With the help of web service, we can create a service for a specific task such as tax calculation.

A Standard protocol for every application program: Web services use standard protocol so that all the client applications written in different languages can understand it. This Standard protocol helps in achieving cross-platform.

Cheaper cost for communication: Web services uses SOAP over HTTP so that anybody can use existing internet for using web services.


Following is a list of main features of web services:

It is available over the Internet or private (intranet) networks.
It uses a standardized XML messaging system.
It is not tied to any one operating system or programming language.
It is self-describing via a common XML grammar.
It is discoverable via a simple find mechanism.



------------------------------------------------- SOAP Web Services -----------------------------------------------


SOAP stands for Simple Object Access Protocol. It is a XML-based protocol for accessing web services.
SOAP is a W3C recommendation for communication between two applications.
SOAP is XML based protocol. It is platform independent and language independent. By using SOAP, you will be able to interact with other programming language applications.


Advantages of Soap Web Services:
WS Security: SOAP defines its own security known as WS Security.
Language and Platform independent: SOAP web services can be written in any programming language and executed in any platform.


Disadvantages of Soap Web Services
Slow: SOAP uses XML format that must be parsed to be read. It defines many standards that must be followed while developing the SOAP applications. So it is slow and consumes more bandwidth and resource.
WSDL dependent: SOAP uses WSDL and doesn't have any other mechanism to discover the service.


------------------------------------------------ RESTful Web Services ---------------------------------------------

RESTful Web Services:

  • REST stands for REpresentational State Transfer.
  • REST is an architectural style not a protocol.

It is developed by Roy Thomas Fielding who also developed HTTP. The main goal of RESTful web services is to make web services more effective. RESTful web services try to define services using the different concepts that are already present in HTTP. REST is an architectural approach, not a protocol.
It does not define the standard message exchange format. We can build REST services with both XML and JSON. JSON is more popular format with REST. The key abstraction is a resource in REST. A resource can be anything. It can be accessed through a Uniform Resource Identifier (URI).
For example:
The resource has representations like XML, HTML, and JSON. The current state is captured by representational resource. When we request a resource, we provide the representation of the resource.
The important methods of HTTP are:
GET: It reads a resource.
PUT: It updates an existing resource.
POST: It creates a new resource.
DELETE: It deletes the resource.

POST /users: It creates a user.

GET /users/{id}: It retrieve the detail of one user.

GET /users: It retrieve the detail of all users.

DELETE /users: It delete all users.

DELETE /users/{id}: It delete a user.

GET /users/{id}/posts/post_id: It retrieve the detail of a specific post.

POST / users/{id}/ posts: It creates a post for a user.

GET /users/{id}/post: Retrieve all posts for a user


HTTP also defines the following standard status code:

404: RESOURCE NOT FOUND
200: SUCCESS
201: CREATED
401: UNAUTHORIZED
500: SERVER ERROR


RESTful Service Constraints :
There must be a service producer and service consumer.
The service is stateless.
The service result must be cacheable.
The interface is uniform and exposing resources.
The service should assume a layered architecture.

Advantages of RESTful web services:
RESTful web services are platform-independent.
It can be written in any programming language and can be executed on any platform.
It provides different data format like JSON, text, HTML, and XML.
It is fast in comparison to SOAP because there is no strict specification like SOAP.
These are reusable.
These are language neutral.



----------------------------------------------------------------------------------------------------------------

There are two popular formats for request and response XML and JSON.

XML Format: XML is the popular form as request and response in web services. Consider the following XML code:

<getDetail>
<id>EmployeeDetail</id>
</getDetail>

The code shows that user has requested to access the EmployeeDetail.



The other data exchange format is JSON. JSON is supported by wide variety of platform.

    "employee": 
   { 
        "id": 20097420
        "name":       "Kavindra",   
        "salary":      15000,   
   } 
]


To make a web service platform-independent, we make the request and response platform-independent.


Now a question arises, how does the Application know the format of Request and Response?

The answer to this question is "Service Definition." Every web service offers a service definition. Service definition specifies the following:

* Request/ Response format: Defines the request format made by consumer and response format made by web service.
* Request Structure: Defines the structure of the request made by the application.
* Response Structure: Defines the structure of response returned by the web service.
* Endpoint: Defines where the services are available.



Key Terminology of Web Services :
* Request and Response
* Message Exchange Format: XML and JSON
* Service Provider or Server
* Service Consumer or Client
* Service Definition
* Transport: HTTP and MQ


Request and Response: Request is the input to a web service, and the response is the output from a web service.

Message Exchange Format: It is the format of the request and response. There are two popular message exchange formats: XML and JSON.

Service Provider or Server: Service provider is one which hosts the web service.

Service Consumer or Client: Service consumer is one who is using the web service.

Service Definition: Service definition is the contract between the service provider and service consumer. Service definition defines the format of request and response, request structure, response structure, and endpoint.

Transport: Transport defines how a service is called. There is two popular way of calling a service: HTTP and Message Queue (MQ). By tying the URL of service, we can call the service over the internet. MQ communicates over the queue.



Keep Learning ! Cheers Guys!!

Kavindra Sahu


2 comments:

  1. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating.

    Oracle SOA Training in Hyderabad
    Oracle SOA Online Training India

    ReplyDelete
  2. Vey very Informative Blog. I found Everything which needed in Webservices.

    ReplyDelete

String to QR Code Image Generator Using Java

 Hi , Hope You are doing well. I came up with the requirement, where I need to generate QR code Image file for the input String. package dem...