SOAP - SOAP Envelope.
1. What is a SOAP Envelope?
-
The Envelope is the root element of every SOAP message.
-
It defines the start and end of the SOAP message.
-
Everything inside a SOAP request or response must be wrapped in an
<Envelope>
. -
Without an Envelope, a message is not valid SOAP.
2. Purpose of SOAP Envelope
-
Acts as a container for the entire SOAP message.
-
Defines the namespace (rules and schema for SOAP messages).
-
Organizes the message into two main parts:
-
Header → metadata (optional).
-
Body → actual data (mandatory).
-
3. Structure of SOAP Envelope
A SOAP Envelope is written in XML. Basic form:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<!-- Optional: authentication, routing, transaction info -->
</soap:Header>
<soap:Body>
<!-- Actual request or response data -->
</soap:Body>
</soap:Envelope>
Parts:
-
Envelope → Root element (mandatory).
-
Header → Extra information like authentication tokens, security, routing (optional).
-
Body → Contains the actual request or response data (mandatory).
4. Example SOAP Request with Envelope
Suppose a client requests a weather report for London:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<auth:Authentication xmlns:auth="http://www.example.com/auth">
<auth:Username>user123</auth:Username>
<auth:Password>pass456</auth:Password>
</auth:Authentication>
</soap:Header>
<soap:Body>
<GetWeather xmlns="http://www.example.com/weather">
<City>London</City>
</GetWeather>
</soap:Body>
</soap:Envelope>
-
Envelope → wraps the whole message.
-
Header → carries authentication info.
-
Body → contains the method
GetWeather
with parameterCity = London
.
5. Example SOAP Response with Envelope
Server responds with weather details:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<GetWeatherResponse xmlns="http://www.example.com/weather">
<City>London</City>
<Temperature>18</Temperature>
<Unit>Celsius</Unit>
</GetWeatherResponse>
</soap:Body>
</soap:Envelope>
6. Key Points about SOAP Envelope
-
Always the outermost element in a SOAP message.
-
Must declare a namespace (
xmlns:soap
). -
Contains Header (optional) and Body (mandatory).
-
Ensures all SOAP messages follow a standard structure.
-
Used in both request and response messages.