According to W3C, A Web service is a software system designed to support interoperable machine-to-machine interaction over a network.
Let's break down the definition into 3 terms
Machine to Machine interaction
- This can be a client-server interaction following the request-response model.
- The client can request information from the server and the server, in turn, responds through a response.
Interoperable
- The interaction should happen on an application-independent format like JSON, XML
Over a Network
- The Communication needs to happen via the HTTP protocol or MQ.
Key Terminologies in Webservices
- Request
- Response
- Service Provider or Server
- Service Consumer or Client
- Service Definition or contract
The Service definition consists of
Request/Response Format, Request/Response Structure and Endpoints.
SOAP WebServices
- SOAP stands for Simple Object Access Protocol.
- It provides a structure for sending our request and response XML Messages.
- It consists of a Soap envelope containing the Soap header and Soap body.
- Sample SOAP XML Message
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"> <soap:Header>
...
</soap:Header>
<soap:Body>
...
<soap:Fault>...</soap:Fault>
</soap:Body>
</soap:Envelope>
- The SOAP protocol follows the WSDL Service Definition.
RestFul Web Services
- REST stands for Representational State Transfer.
- The Restful web services are more like an architectural way of developing web services(resources) and expose them using HTTP.
- It makes the best use of the HTTP protocol for communication between the client and the server.
- Check out the below link for a detailed explanation of the HTTP protocol.
- The data exchange format can be anything like XML, JSON, HTML, etc
- There is no standard service definition. We can use Swagger etc.