SOAP Header Element

Optional SOAP Header elements contain header information.

SOAP Header Element

Optional SOAP Header elements can contain application-specific information about the SOAP message (such as authentication, payment, etc.). If the Header element is provided, it must be the first child of the Envelope element.

Note:All direct children of the Header element must be in a valid namespace.

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"
<soap:Header>
<m:Trans
xmlns:m="http://www.codew3c.com/transaction/"
soap:mustUnderstand="1">234</m:Trans>
</soap:Header>
...
...
</soap:Envelope>

The above example includes a header with a "Trans" element, whose value is 234, and the "mustUnderstand" attribute of this element is set to "1".

SOAP defines three attributes in the default namespace ("http://www.w3.org/2001/12/soap-envelope"). These three attributes are: actor, mustUnderstand, and encodingStyle. These attributes defined in the SOAP header can define how the container processes the SOAP message.

actor attribute

By traversing different endpoints along the message path, SOAP messages can be propagated from a sender to a receiver. Not all parts of the SOAP message are intended to be delivered to the final endpoint of the SOAP message, however, on the other hand, they may be intended to be delivered to one or more endpoints along the message path.

The SOAP actor attribute can be used to address the Header element to a specific endpoint.

Syntax

soap:actor="URI"

Example

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"
<soap:Header>
<m:Trans
xmlns:m="http://www.codew3c.com/transaction/"
soap:actor="http://www.codew3c.com/appml/">
234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>

mustUnderstand Attribute

The mustUnderstand attribute of SOAP can be used to identify whether a header item is mandatory or optional for the receiver who is to process it.

If you add "mustUnderstand="1" to a child element of the Header element, it can indicate that the receiver who processes this header must recognize this element. If this receiver cannot recognize this element, it must be invalid when processing this header.

Syntax

soap:mustUnderstand="0|1"

Example

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"
<soap:Header>
<m:Trans
xmlns:m="http://www.codew3c.com/transaction/"
soap:mustUnderstand="1">
234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>

encodingStyle Attribute

The encodingStyle attribute of SOAP has been explained in the previous section.