Engineering Full Stack Apps with Java and JavaScript
WebServices can be roughly divided into two types based on the architecture they follow:
SOAP-based web services
Restful web services
SOAP-based web services were the original kind of web services
They follow RPC-style
An RPC-style web service accepts an envelope full of data from its client, and sends a similar envelope back.
The method and the scoping information are kept inside the envelope. HTTP is a popular envelope format.
SOAP is another popular envelope format (transmitting a SOAP document over HTTP puts the SOAP envelope inside an HTTP envelope).
SOAP Services can be located and invoked by client applications over a network (e.g. internet) automatically without human interaction.
To make the automatic locating and invocation possible SOAP web services were designed as self describing through the use of a message protocol called SOAP, service definition called WSDL and a way to locate other web services using UDDI.
SOAP web services are self-describing and self-contained, as the definition of the message format (WSDL and/or XSD) travels with the message or is accessible to the client, and the server and client requires only minimal software - an HTTP server and/or a SOAP server on the server side and on the client side no additional s/w is required.
SOAP is based on rules whereas REST is based on guidelines.
SOAP web service defines a new vocabularies, standards and protocols.
In SOAP based webservices messages (requests and responses) are exchanged in an XML format called SOAP.
SOAP originally stood for Simple Object Access Protocol, but now some also call it as Service Oriented Architecture (SOA) protocol.
Though HTTP is the most commonly used protocol with SOAP-based webservices, it is not limited to just HTTP, but can also use other protocols like SMTP, JMS etc.
A SOAP-based service delivered over HTTP can be considered as a special case of a REST-style service.
In SOAP, the endpoint url will be same for a service that represent a set of operations and different operations are requested using specifics in the request body.
Definition about the service is stored in a document called WSDL in case of SOAP. When a client get a wsdl, it will have all information regarding a SOAP web service.
The request-response pattern is supported by both SOAP and REST. SOAP based services also support other message exchange patterns like one way input, solicit response and publish-subscribe.
You need a specialized client that can send SOAP requests in case of SOAP.
SOAP UI is a popular tool that can do this.
You may also write a Java client using JAX-WS on your own.
Restful web services came later and is more popular now
They follow a resource oriented way. Every resource will be reprecented by an URI and its current state of representation is transferred using formats such as XML and JSON.
REST web services are not automatically located using an UDDI registry as in case of SOAP web services.
SOAP is based on rules whereas REST is based on guidelines
Restful web services share a standard vocabulary of HTTP methods.
Every object in a Restful service responds to the same basic interface.
In a REST-style service, a client might send a standard HTTP request to a web service and receives an appropriate response in a MIME-TYPE of their choice like XML, Text, JSON, user-defined etc.
HTTP is the only transport protocol for REST.
REST usually have a single url for a resource and uses the standard set of http operations like POST, GET, PUT, and DELETE, to do various operations on that resource.
Note that REST is based on guidelines and not rules as in the case of SOAP. So there is nothing which will enforce you to use a particular approach in REST, like in the case of SOAP.
There is no formal definitions for REST like the WSDL for SOAP. There are some definition formats like WADL, but they have not become very popular.
REST support only request-response message exchange pattern.
You can make requests to a RESTful web service using your programming language’s HTTP client library or even from your web browser if it is a GET request.
There are also plugins available to most browsers.