SOAP (Simple Object Access Protocol) is a protocol for exchanging XML-based messages over computer networks using commonly known protocols such as HTTP, HTTPS, and SMTP. It serves as the foundation for delivering basic messages in web services.
There are several message patterns, but typically SOAP follows the Remote Procedure Call (RPC) pattern, where a network node (client) sends a message to another node (server) and the server immediately responds. SOAP adopted the concept of an envelope/header/body structure and the principles of transport and interaction neutrality from XML-RPC and WDDX.
SOAP is designed based on the combination of headers and bodies, with XML as its foundation. The header is optional and contains metadata such as repetition, security, and transactional information. The body contains the main information, which is essential to the message.
Advantages of SOAP:
Communication Ease: SOAP allows for easy communication without being restricted by proxies or firewalls, unlike traditional remote technologies.
Platform and Language Independence: SOAP is platform and programming language independent, meaning it can be used across different systems and languages without compatibility issues.
Established Standards: SOAP has well-established standards for providing web services, such as WSDL (Web Services Description Language), UDDI (Universal Description, Discovery, and Integration), and WS-* (Web Services specifications). These standards ensure interoperability and facilitate the integration of different systems.
Built-in Error Handling: SOAP includes built-in error handling mechanisms, making it easier to handle and manage errors during the communication process.
Suitable for Distributed Environments: SOAP is well-suited for distributed environments where multiple systems need to interact and exchange data. It provides a standardized way of communication in such environments.
Disadvantages of SOAP:
Complexity and Overhead: SOAP has a complex structure and includes additional overhead due to its XML-based messaging format. This complexity can hinder scalability and performance, especially when dealing with large volumes of data.
Slower Speed: Compared to lightweight alternatives like REST (Representational State Transfer), SOAP is relatively heavier and can be slower in terms of data transmission and processing. The additional XML parsing and message formatting contribute to the slower speed.
Higher Development Complexity: Developing SOAP-based applications can be more challenging compared to other web service protocols. SOAP requires specific libraries or frameworks, and developers need to have a good understanding of the underlying SOAP specifications. This can increase development time and complexity.
SOAP Architecture:
SOAP architecture involves registering (Publishing), searching (Finding), and binding (Binding) web services through UDDI.
<?xml version='1.0' Encoding='UTF-8' ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header>
<m:reservation xmlns:m="https://www.website.com/reservation" env:role="http://www.w3.org/2003/05/soap-envelope/role/next">
<m:reference>uuid:11111-22222-333333-444444-555555</m:reference>
<m:dateAndTime>2020-01-01</m:dateAndTime>
</m:reservation>
<n:passenger xmlns:n="https://www.website.com/employees" env:role="http://www.w3.org/2003/05/soap-envelope/role/next">
<n:name>John Smith</n:name>
</n:passenger>
</env:Header>
<env:Body>
<p:itinerary xmlns:p="https://www.website.com/reservation/travel">
<p:departure>
<p:departing>New York</p:departing>
<p:arriving>Los Angeles</p:arriving>
<p:departureDate>2020-01-01</p:departureDate>
</p:departure>
</p:itinerary>
</env:Body>
</env:Envelope>
Example:
POST /xml/tempconvert.asmx HTTP/1.1
Host: www.website.com
Content-Type: application/soap+xml
Content-Length: 349
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<GetUserBalance xmlns="https://www.website.com/xml/">
<UserId>75</UserId>
</GetUserBalance>
</soap:Body>
</soap:Envelope>
Operation of SOAP:
The service requester encodes the web service request in SOAP and sends it to the service provider. The service provider decodes the request, performs the appropriate service logic to obtain the result, encodes the result in SOAP, and returns it.
SOAP Message Structure:
A SOAP message is an XML document composed of an optional Header and a mandatory Body enclosed within an Envelope. The Fault within the Body is used for error reporting.
SOAP Envelope: The Envelope is the root element of every SOAP message and contains two sub-elements: an optional Header and a mandatory Body.
SOAP Header: The Header is an optional sub-element of the Envelope and is used to convey application-specific information that is processed only by SOAP nodes along the message path.
SOAP Body: The Body is a mandatory sub-element of the Envelope and contains the information targeted at the ultimate recipient of the message.
SOAP Fault: Fault is a sub-element of the Body and is used for reporting errors.