A Web Service is a software application identified by a URI (Uniform Resource Identifier) whose interfaces and binding are capable of being defined, described and discovered by XML artifacts and [that] supports direct interactions with other software applications using XML based messages via Internet-based protocols (HTTP, HTTPS, SMTP).

Web Service relies on Simple Object Application Protocol (SOAP) as its transport.

A Web Service is can be defined by following ways:

  • is a client server application or application component for communication.
  • method of communication between two devices over network.
  • is a software system for interoperable machine to machine communication.
  • is a collection of standards or protocols for exchanging information between two devices or application.

There are mainly two types of web services.

  1. SOAP web services.
  2. RESTful web services.

There are three major web service components.

  1. SOAP
  2. WSDL
  3. UDDI

SOAP

SOAP is an acronym for Simple Object Access Protocol.

SOAP is a XML-based protocol for accessing web services.

SOAP is a W3C recommendation for communication between applications.

SOAP is XML based, so it is platform independent and language independent. In other words, it can be used with Java, .Net or PHP language on any platform.

WSDL

WSDL is an acronym for Web Services Description Language.

WSDL is a xml document containing information about web services such as method name, method parameter and how to access it.

WSDL is a part of UDDI. It acts as a interface between web service applications.

Web Service Description Language (WSDL) specifies the service interface and the rules for binding the service consumer and the provider.

UDDI

UDDI is an acronym for Universal Description, Discovery and Integration.

UDDI is a XML based framework for describing, discovering and integrating web services.

UDDI is a directory of web service interfaces described by WSDL, containing information about web services.

RESTful Web Services

REST stands for REpresentational State Transfer.

REST is an architectural style not a protocol.

REST enforces a stateless client server design where web services are treated as resource and can be accessed and identified by there URL unlike SOAP web services which were defined by WSDL.

Web services written by REST Architectural concept are called RESTful web services which focus on System resources and how state of Resource should be transferred over http protocol to a different clients written in different languages.

Advantages of RESTful Web Services

Fast: RESTful Web Services are fast because there is no strict specification like SOAP. It consumes less bandwidth and resource.

Language and Platform independent: RESTful web services can be written in any programming language and executed in any platform.

Can use SOAP: RESTful web services can use SOAP web services as the implementation.

Permits different data format: RESTful web service permits different data format such as Plain Text, HTML, XML and JSON.

 

Java web service application perform communication through WSDL (Web Services Description Language). There are two ways to write java web service application code: SOAP and RESTful.

Java Web Services API

There are two main API's defined by Java for developing web service applications since JavaEE 6.

1) JAX-WS: for SOAP web services. The are two ways to write JAX-WS application code: by RPC style and Document style.

2) JAX-RS: for RESTful web services. There are mainly 2 implementation currently in use for creating JAX-RS application: Jersey and RESTeasy.

RESTfull web services are much more simpler, flexible and expressive than SOAP web services in Java.

REST takes full advantage of HTTP protocol, including methods e.g. GET, POST, PUT, and DELETE to represent action. Thus, REST uses HTTP for all four CRUD (Create/Read/Update/Delete) operations.

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.

The main differences between REST and SOAP web service

Though both RESTful web series and SOAP web service can operate cross platform they are architecturally different to each other, here is some of differences between REST and SOAP:

1) REST is more simple and easy to use than SOAP. REST language is based on use of nouns and verbs (better readability)

2) REST uses HTTP protocol for producing or consuming web services while SOAP uses XML.

   The SOAP WS is transport protocol neutral. Supports multiple protocols like HTTP(S), Messaging, TCP, UDP SMTP, etc.

   The REST is transport protocol specific. Supports only HTTP or HTTPS protocols.

3) REST is lightweight as compared to SOAP and preferred choice in mobile devices and PDA’s. REST does not need XML parsing, no message header (to and from), hence less bandwidth

4) REST supports different format like text, JSON and XML while SOAP only support XML.

   The SOAP WS permits only XML data format.You define operations, which tunnels through the POST. The focus is on accessing the named operations and exposing the application logic as a service.

   The REST permits multiple data formats like XML, JSON data, text, HTML, etc. Any browser can be used because the REST approach uses the standard GET, PUT, POST, and DELETE Web operations. The focus is on accessing the named resources and exposing the data as a service. REST has AJAX support. It can use the XMLHttpRequest object. Good for stateless CRUD (Create, Read, Update, and Delete) operations.

   GET – represent(); POST – acceptRepresention(); PUT – storeRepresention(); DELETE – removeRepresention()

5) REST works with resources, each unique URL is some representation of a resource; SOAP works with operations, which implement some business logic through different interfaces.

6) SOAP based reads cannot be cached. REST based reads can be cached. Performs and scales better.

7) Different error handling:

   REST: requires HTTP error handling
   SOAP: can have user defined error

8) REST only supports synchronous message because of its reliance of HTTP and HTTPS

9) SOAP WS supports both SSL security and WS-security, which adds some enterprise security features like maintaining security right up to the point where it is needed, maintaining identities through intermediaries and not just point to point SSL only, securing different parts of the message with different security algorithms, etc.

   The REST supports only point-to-point SSL security. The SSL encrypts the whole message, whether all of it is sensitive or not.

10) The SOAP has comprehensive support for both ACID based transaction management for short-lived transactions and compensation based transaction management for long-running transactions. It also supports two-phase commit across distributed resources.

   The REST supports transactions, but it is neither ACID compliant nor can provide two phase commit across distributed transactional resources as it is limited by its HTTP protocol.

11) The SOAP has success or retry logic built in and provides end-to-end reliability even through SOAP intermediaries. REST does not have a standard messaging system, and expects clients invoking the service to deal with communication failures by retrying.