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:

  1. Envelope → Root element (mandatory).

  2. Header → Extra information like authentication tokens, security, routing (optional).

  3. 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 parameter City = 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

  1. Always the outermost element in a SOAP message.

  2. Must declare a namespace (xmlns:soap).

  3. Contains Header (optional) and Body (mandatory).

  4. Ensures all SOAP messages follow a standard structure.

  5. Used in both request and response messages.