SOAP - SOAP Body

1. What is SOAP Body?

  • The SOAP Body is the main and mandatory part of a SOAP message.

  • It carries the actual request (when the client is calling a service) or the actual response (when the server replies).

  • Unlike the Header, the Body must always be present in a SOAP message.


2. Purpose of SOAP Body

  • Contains the application-specific data being exchanged.

  • For request messages: holds the operation (method) being invoked and its parameters.

  • For response messages: holds the results or output of the operation.

  • Also carries Fault messages if an error occurs.


3. Structure of SOAP Body

A SOAP Body is an XML element <soap:Body> inside the Envelope.

Example – SOAP Request (Client → Server):

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Header/>
   <soap:Body>
      <GetWeather xmlns="http://www.example.com/weather">
         <City>London</City>
      </GetWeather>
   </soap:Body>
</soap:Envelope>
  • The <GetWeather> method is being called with parameter City = London.


Example – SOAP Response (Server → Client):

<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>
  • The server responds with temperature information (18 Celsius).


4. SOAP Fault in Body

If an error occurs, the Fault element is placed inside the Body:

<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>
  • Faultcode: type of error (e.g., Client, Server).

  • Faultstring: human-readable description.


5. Key Points about SOAP Body

  1. Mandatory – every SOAP message must have a Body.

  2. Contains actual data – request or response information.

  3. Can hold one operation at a time – usually matches WSDL-defined methods.

  4. Namespace required – to uniquely identify the operation.

  5. Fault handling – Body also carries <Fault> messages when errors happen.


6. Summary

  • SOAP Header = metadata/instructions (optional).

  • SOAP Body = actual message data (mandatory).

  • SOAP Fault (inside Body) = standard error handling mechanism.