When using the WCF adapter, I have the message body part being send as the body of the WCF message, but can I do to get the Biztalk message context to be sent as well (hopefully within the WCF message header)?
问题:
回答1:
The following page in MSDN succinctly explains how you can use custom SOAP headers when sending messages outside BizTalk with the WCF adapters.
Basically, you cannot directly send the context of your BizTalk messages outside BizTalk. This would be meaningless. Rather, you can select a subset of the properties in the context of your BizTalk messages to be sent to the WCF adapter through custom SOAP headers.
Handling Custom SOAP Headers Outgoing WCF Request
SOAP headers associated with an outgoing request must explicitly be written to the context of the outgoing message.
When using the WCF Adapters, SOAP Headers are defined with the built-in WCF.OutboundCustomHeaders context property. This property holds all custom SOAP headers, wrapped inside an additional <headers> tag.
Headers can be specified from within an orchestration with the following syntax in an Expression shape:
OutboundMessage(WCF.OutboundCustomHeaders) = "" +
"<headers>"
"<tns1:Header1 xmlns:tns1='http://tns1'>" +
"</tns1:Header1>" +
"<tns2:Header2 xmlns:tns2='http://tns2'>" +
"</tns2:Header2>" +
"</headers>" +
"";
Please, note that the custom SOAP Headers <tns1:Header1> and <tns2:Header2> used for illustration purposes above must be part of your WCF service contract. When you create a service reference for the consumed WCF service, those custom SOAP headers will be available as generated schemas in your orchestration.
How to Send Specific Context Properties in Custom SOAP Header
Now that you know how to specify custom SOAP Headers, you can use this syntax to send specific properties from the context of your messages to the custom SOAP headers like so:
OutboundMessage(WCF.OutboundCustomHeaders) =
System.String.Format(
"" +
"<headers>"
"<tns1:Header1 xmlns:tns1='http://tns1'>" +
" <tns1:Property1>{0}</tns1:Property1>" +
" <tns1:Property2>{1}</tns1:Property2>" +
"</tns1:Header1>" +
"</headers>" +
""
, InboundMessage(FILE.ReceivedFileName)
, InboundMessage(BTS.MessageType)
));
In the example above, the two builtin context properties FILE.ReceivedFileName and BTS.MessageType have been selected and written inside the custom SOAP header. In a real world scenario, you would want to check whether the properties exist in the context before using them.
You can also use any custom context property, provided they have been declared in an appropriate Property Schema.