- Contents
SOAP API Developer's Guide
Header Section
As mentioned earlier, the envelope can contain header and body sections. These are defined using Header and Body elements. Listing 3 shows a SOAP message with empty Header and Body sections.
Listing 3: Header and Body Sections of a SOAP Envelope
1 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
2 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
3 <SOAP-ENV:Header>
4 </SOAP-ENV:Header>
5 <SOAP-ENV:Body>
6 </SOAP-ENV:Body>
7 </SOAP-ENV:Envelope>
As you can see, lines 3-4 define the Header section. Lines 5-6 define the Body. Other independent elements can optionally be defined inside the envelope, but for purposes of this discussion, we do not need to be concerned with independent elements. Refer to the W3C SOAP Specification at http://www.w3.org/TR/SOAP/ for more information about independent elements.
The Header section can contain meta data about the message. Meta data is "data that describes data". A SOAP message does not have to contain a Header. Header elements make it possible to extend the base SOAP protocol, to accommodate needs that the SOAP specification does not include.
For example, Header elements might maintain session information between a server and a client, or might contain authentication information about a transaction. A Header can contain any number of namespace-qualified child elements, each of which extends the default protocol in some way. Each header element provides extra content for processing the Body of the message.
Each Header element may be annotated with a "mustUnderstand" attribute, which indicates whether or not the element is mandatory. When "mustUnderstand" is True for an element, the server that processes the message must know how to interpret that element. If it doesn't, it must reject the message. Headers that do not have a "mustUnderstand" attribute, or which have this attribute set False, are considered to be optional, meaning that the recipient server is allowed to process the message as best it can.