7.2. Adding Headers to a SOAP 1.2 Message
Overview
soap12:header elements to your SOAP 1.2 message. The soap12:header element is an optional child of the input, output, and fault elements of the binding. The SOAP header becomes part of the parent message. A SOAP header is defined by specifying a message and a message part. Each SOAP header can only contain one message part, but you can insert as many headers as needed.
Syntax
Example 7.3. SOAP Header Syntax
<binding name="headwig">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="weave">
<soap12:operation soapAction="" style="documment"/>
<input name="grain">
<soap12:body ... />
<soap12:header message="QName" part="partName"
use="literal|encoded"
encodingStyle="encodingURI"
namespace="namespaceURI" />
</input>
...
</binding>soap12:header element’s attributes are described in Table 7.1, “soap12:header Attributes”.
Table 7.1. soap12:header Attributes
Splitting messages between body and header
soap12:body element has an optional attribute, parts, that takes a space delimited list of part names. When parts is defined, only the message parts listed are inserted into the body of the SOAP 1.2 message. You can then insert the remaining parts into the message's header.
Example
orderWidgets service shown in Example 7.1, “Ordering System Interface”. This version is modified so that each order has an xsd:base64binary value placed in the header of the request and the response. The header is defined as being the keyVal part from the widgetKey message. In this case you are responsible for adding the application logic to create the header because it is not part of the input or output message.
Example 7.4. SOAP 1.2 Binding with a SOAP Header
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="widgetOrderForm.wsdl"
targetNamespace="http://widgetVendor.com/widgetOrderForm"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://widgetVendor.com/widgetOrderForm"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsd1="http://widgetVendor.com/types/widgetTypes"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<types>
<schema targetNamespace="http://widgetVendor.com/types/widgetTypes"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<element name="keyElem" type="xsd:base64Binary"/>
</schema>
</types>
<message name="widgetOrder">
<part name="numOrdered" type="xsd:int"/>
</message>
<message name="widgetOrderBill">
<part name="price" type="xsd:float"/>
</message>
<message name="badSize">
<part name="numInventory" type="xsd:int"/>
</message>
<message name="widgetKey">
<part name="keyVal" element="xsd1:keyElem"/>
</message>
<portType name="orderWidgets">
<operation name="placeWidgetOrder">
<input message="tns:widgetOrder" name="order"/>
<output message="tns:widgetOrderBill" name="bill"/>
<fault message="tns:badSize" name="sizeFault"/>
</operation>
</portType>
<binding name="orderWidgetsBinding" type="tns:orderWidgets">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="placeWidgetOrder">
<soap12:operation soapAction="" style="document"/>
<input name="order">
<soap12:body use="literal"/>
<soap12:header message="tns:widgetKey" part="keyVal"/>
</input>
<output name="bill">
<soap12:body use="literal"/>
<soap12:header message="tns:widgetKey" part="keyVal"/>
</output>
<fault name="sizeFault">
<soap12:body use="literal"/>
</fault>
</operation>
</binding>
...
</definitions>keyVal is a part of the input and output messages. In the soap12:body elements the parts attribute specifies that keyVal should not be inserted into the body. However, it is inserted into the header.
Example 7.5. SOAP 1.2 Binding for orderWidgets with a SOAP Header
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="widgetOrderForm.wsdl"
targetNamespace="http://widgetVendor.com/widgetOrderForm"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://widgetVendor.com/widgetOrderForm"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsd1="http://widgetVendor.com/types/widgetTypes"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<types>
<schema targetNamespace="http://widgetVendor.com/types/widgetTypes"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<element name="keyElem" type="xsd:base64Binary"/>
</schema>
</types>
<message name="widgetOrder">
<part name="numOrdered" type="xsd:int"/>
<part name="keyVal" element="xsd1:keyElem"/>
</message>
<message name="widgetOrderBill">
<part name="price" type="xsd:float"/>
<part name="keyVal" element="xsd1:keyElem"/>
</message>
<message name="badSize">
<part name="numInventory" type="xsd:int"/>
</message>
<portType name="orderWidgets">
<operation name="placeWidgetOrder">
<input message="tns:widgetOrder" name="order"/>
<output message="tns:widgetOrderBill" name="bill"/>
<fault message="tns:badSize" name="sizeFault"/>
</operation>
</portType>
<binding name="orderWidgetsBinding" type="tns:orderWidgets">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="placeWidgetOrder">
<soap12:operation soapAction="" style="document"/>
<input name="order">
<soap12:body use="literal" parts="numOrdered"/>
<soap12:header message="tns:widgetOrder" part="keyVal"/>
</input>
<output name="bill">
<soap12:body use="literal" parts="bill"/>
<soap12:header message="tns:widgetOrderBill" part="keyVal"/>
</output>
<fault name="sizeFault">
<soap12:body use="literal"/>
</fault>
</operation>
</binding>
...
</definitions>
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.