SOAP - How SOAP works
1. SOAP Workflow (How it works)
SOAP works in a request–response model:
-
Client prepares a SOAP request
-
The client (e.g., an application) creates an XML message inside a SOAP envelope.
-
This message describes what service or method it wants to call, and what data it’s sending.
-
-
Request sent over a protocol (HTTP/SMTP/etc.)
-
The message is sent to the server (usually over HTTP).
-
-
Server processes the request
-
The server receives the SOAP message, extracts the data, and executes the required operation.
-
-
Server sends a SOAP response
-
The server prepares another XML message with the result (or an error in a
<Fault>
block).
-
-
Client receives and interprets the response
-
The client parses the XML and uses the returned data.
-
2. SOAP Structure Reminder
Every SOAP message is an XML document with four main parts:
-
<Envelope>
→ Root element (mandatory). -
<Header>
→ Metadata like authentication, routing (optional). -
<Body>
→ Actual request/response data (mandatory). -
<Fault>
→ Error handling (optional).
3. Simple Example: Get Temperature of a City
Step A: Client sends request
Suppose a client wants to get the temperature for London from a weather web service.
SOAP request message:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<GetTemperature xmlns="http://www.example.com/weather">
<City>London</City>
</GetTemperature>
</soap:Body>
</soap:Envelope>
-
Envelope
: Defines the SOAP message. -
Body
: Contains the method (GetTemperature
) and its parameter (City = London
).
Step B: Server processes request
-
The server sees that the client is calling the method GetTemperature.
-
It looks up London’s temperature (say 18°C).
Step C: Server sends response
SOAP response message:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<GetTemperatureResponse xmlns="http://www.example.com/weather">
<City>London</City>
<Temperature>18</Temperature>
<Unit>Celsius</Unit>
</GetTemperatureResponse>
</soap:Body>
</soap:Envelope>
-
The server wraps the response data (temperature = 18°C) inside the SOAP Body.
Step D: Client receives response
-
The client application reads the XML, extracts
Temperature = 18, Unit = Celsius
, and displays it.
4. Error Handling Example (Fault)
If something goes wrong (e.g., invalid city name), the server responds with a SOAP Fault:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Invalid city name</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
5. Summary of How SOAP Works
-
Client creates a SOAP XML request.
-
Request sent to the server over HTTP (or other protocol).
-
Server parses XML, executes the service.
-
Server sends back a SOAP XML response.
-
Client reads and processes the result.