SOAP - introduction to SOAP (Simple Object Access Protocol)
1. What is SOAP?
-
SOAP is a protocol used for exchanging structured information in web services over the internet.
-
It relies on XML (Extensible Markup Language) to format the data.
-
SOAP can work over many protocols like HTTP, SMTP, TCP, or even JMS, though HTTP is most common.
2. Key Features
-
Platform and language independent (Java, .NET, Python, etc. can communicate).
-
Uses XML for request and response messages.
-
Extensible – supports security, transactions, etc. via standards (WS-Security, WS-AtomicTransaction).
-
Neutral transport – not tied to a specific network protocol.
3. SOAP Message Structure
A SOAP message is always an XML document with the following parts:
<soap:Envelope>
<soap:Header>
<!-- Optional metadata, e.g., authentication info -->
</soap:Header>
<soap:Body>
<!-- Main message/request/response -->
</soap:Body>
<soap:Fault>
<!-- Error messages (optional) -->
</soap:Fault>
</soap:Envelope>
-
Envelope: Root element, defines the start and end of the message.
-
Header: Optional, contains metadata (security, routing, etc.).
-
Body: Mandatory, contains actual request or response data.
-
Fault: Optional, used when errors occur.
4. Example SOAP Request
Here’s a simple SOAP request to get the weather for a city:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetWeather>
<City>New York</City>
</GetWeather>
</soap:Body>
</soap:Envelope>
5. SOAP vs REST (basic difference)
-
SOAP: Protocol, uses XML only, more rigid, supports advanced features (security, transactions).
-
REST: Architectural style, usually uses JSON (or XML), simpler and faster, commonly used in modern APIs.