SOAP Headers with Published WCF Services

The WCF receive adapters can copy all the SOAP header values in the inbound messages to the InboundHeaders property, or they can write or promote specified values to the BizTalk message context. The adapters can work with both custom SOAP headers and standard SOAP headers that the WCF infrastructure uses, such as WS-Addressing, WS-Security, and WS-AtomicTransaction. The InboundHeaders context property is in the target namespace, and contains string representations of the SOAP header values in inbound messages.


If you are going to promote the SOAP header values you specified, there must be a deployed property schema in your BizTalk project that corresponds to the values you are promoting.


The promoted properties cannot be longer than 256 characters.

The following XML data shows an example of the string representation of the SOAP headers for the InboundHeaders property. This comes from the client and is sent to the BizTalk receive location.

<a:Action s:mustUnderstand="1" xmlns:s="" xmlns:a="">Operation_1</a:Action>  
<SalesAgent xmlns="Microsoft.Samples.BizTalk.WCF.CustomSoapHeaderPipeline">Contoso</SalesAgent>  
<a:MessageID xmlns:a="">urn:uuid:26e6720f-5a82-4ef2-b597-6ef077bab92e</a:MessageID>  
<a:ReplyTo xmlns:a=""><a:Address></a:Address></a:ReplyTo>  
<a:To s:mustUnderstand="1" xmlns:s="" xmlns:a="">net.tcp://localhost:9990/NetTcpOrderProcess</a:To>  

To write or promote SOAP header values to the BizTalk message context, you need to put a collection of value pairs that consist of property name and namespace into the WCF message so that the WCF adapters will recognize that the header values are to be written or promoted. A WCF adapter expects the following message properties in the WCF messages for writing or promoting SOAP header values to the BizTalk message context:

const string PropertiesToPromoteKey="";  
const string PropertiesToWriteKey="";  

XmlQualifiedName PropName1=new XmlQualifiedName("Destination", "");  
XmlQualifiedName PropName2=new XmlQualifiedName("Source", "");  

//Create a List of KeyValuePairs that indicate properties to be promoted to BizTalk message context.   
//A Property Schema must be deployed and string values have a limit of 256 characters  
List<KeyValuePair<XmlQualifiedName, object>> promoteProps=new List<KeyValuePair<XmlQualifiedName, object>>();  
promoteProps.Add(new KeyValuePair<XmlQualifiedName, object>(PropName1, "Property value"));  

//Create a List of KeyValuePairs that indicate properties to be written to BizTalk message context  
List<KeyValuePair<XmlQualifiedName, object>> writeProps=new List<KeyValuePair<XmlQualifiedName, object>>();  
writeProps.Add(new KeyValuePair<XmlQualifiedName, object>(PropName2, "Property value"));  

The BizTalk WCF Service Publishing Wizard does not include custom SOAP header definitions in the generated metadata. To publish metadata for WCF services using custom SOAP headers, you should manually create a Web Services Description Language (WSDL) file. You can use the externalMetadataLocation attribute of the <serviceMetadata> element in the Web.config file that the wizard generates to specify the location of the WSDL file. The WSDL file is returned to the user in response to WSDL and metadata exchange (MEX) requests instead of the auto-generated WSDL.

The following XML data shows an example of a part of the WSDL file defining custom SOAP headers:

<wsdl:operation name="Request">  
  <soap12:operation soapAction="http://Microsoft.Samples.BizTalk.NetTcpAdapter/OrderProcess/IOrderProcess/Request" style="document" />   
   <wsdl:input name="Order">  
     <soap12:header message="i0:Order_Headers" part="SalesAgent" use="literal" />   
     <soap12:body use="literal" />   
   <wsdl:output name="OrderConfirmation">  
     <soap12:header message="i0:OrderConfirmation_Headers" part="PaymentAgent" use="literal" />   
     <soap12:body use="literal" />   

In This Section

See Also

WCF Adapters Property Schema and Properties
SOAP Headers with Consumed WCF Services