SOAP - SOAP Header

1. What is a SOAP Header?

  • The SOAP Header is an optional part of a SOAP message.

  • It appears inside the Envelope, before the Body.

  • Used to carry metadata (extra information) about the message, not the actual business data.

  • If no Header is needed, it can be left empty or omitted.


2. Purpose of SOAP Header

  • Provides context for how the SOAP message should be processed.

  • Common uses:

    • Authentication (username, password, tokens).

    • Security (encryption, digital signatures).

    • Routing information (where the message should go).

    • Transaction management.

    • Quality of Service (QoS) details (e.g., message reliability).


3. Structure of SOAP Header

The <soap:Header> element contains child elements, each representing a piece of metadata.

Example (simple authentication in Header):

<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>

4. Attributes of SOAP Header Elements

Each header block can have attributes that define how it should be handled:

  • mustUnderstand

    • If set to 1, the receiver must process this header.

    • If it cannot, it should return a Fault.
      Example:

    <auth:Authentication xmlns:auth="http://www.example.com/auth" soap:mustUnderstand="1">
       <auth:Username>user123</auth:Username>
       <auth:Password>pass456</auth:Password>
    </auth:Authentication>
    
  • actor / role

    • Specifies which node should process the header (useful in message routing).

    • Example:

    <transaction:ID xmlns:transaction="http://www.example.com/txn" soap:actor="http://intermediary.com">
       12345
    </transaction:ID>
    

5. Key Points about SOAP Header

  1. Optional – may or may not be present.

  2. Multiple headers allowed – one SOAP message can have many header blocks.

  3. Independent of Body – headers contain meta info, not actual service data.

  4. Supports mustUnderstand – ensures critical headers are processed.

  5. Used in advanced features – like security (WS-Security), routing, and transactions.


6. Summary

  • SOAP Header = metadata container.

  • Goes before the Body in a SOAP message.

  • Carries extra instructions (authentication, routing, transactions, etc.).

  • Makes SOAP extensible and powerful for enterprise applications.