After giving an introduction to SOAP in the previous article, in this article, we would discuss some important elements and attributes of SOAP. We start with the header element. The SOAP Header element contains application-specific information (like authentication, payment, etc) about the SOAP message. The header element should be the first child element of the Envelope element and all immediate child elements of the Header element must be namespace-qualified. Consider the following piece of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.google.com/2001/12/soap-envelope" soap:encodingStyle="http://www.google.com/2001/12/soap-encoding"> <soap:Header> <m:Trans xmlns:m="http://www.gmail.com/transaction/" soap:mustUnderstand="1">234 </m:Trans> </soap:Header> ... ... </soap:Envelope> |
The example above contains a header with a “Trans” element, a “mustUnderstand” attribute with a value of 1, and a value of 234. The attributes defined in the SOAP Header defines how a recipient should process the SOAP message.
An important attribute is the SOAP mustUnderstand attribute which can be used to indicate whether a header entry is mandatory or optional for the recipient to process. If you add mustUnderstand=”1″ to a child element of the Header element it indicates that the receiver processing the Header must recognize the element. If the receiver does not recognize the element it will fail when processing the Header. It’s syntax is:
soap:mustUnderstand=”0|1″
An example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.google.com/2001/12/soap-envelope" soap:encodingStyle="http://www.google.com/2001/12/soap-encoding"> <soap:Header> <m:Trans xmlns:m="http://www.gmail.com/transaction/" soap:mustUnderstand="1">234 </m:Trans> </soap:Header> ... ... </soap:Envelope> |
A SOAP message may travel from a sender to a receiver by passing different endpoints along the message path. However, not all parts of a SOAP message may be intended for the ultimate endpoint, instead, it may be intended for one or more of the endpoints on the message path. The SOAP actor attribute is used to address the Header element to a specific endpoint. Its syntax is:
soap:actor=”URI”
Consider an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.google.com/2001/12/soap-envelope" soap:encodingStyle="http://www.google.com/2001/12/soap-encoding"> <soap:Header> <m:Trans xmlns:m="http://www.gmail.com/transaction/" soap:actor="http://www.gmail.com/appml/">234 </m:Trans> </soap:Header> ... ... </soap:Envelope> |
The following line in the above code:
soap:actor=”http://www.gmail.com/appml/”>234
is used to address the Header element to the desired endpoint.