SOAP 标头与发布的 WCF 服务

WCF 接收适配器可以将入站消息中的所有 SOAP 标头值复制到 InboundHeaders 属性,也可以将指定值写入 BizTalk 消息上下文或将指定值提升到 BizTalk 消息上下文。 这些适配器可以处理 WCF 基础结构使用的自定义 SOAP 标头和标准 SOAP 标头,如 WS-Addressing、WS-Security 和 WS-AtomicTransaction。 InboundHeaders 上下文属性位于目标命名空间 http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties中,包含入站消息中 SOAP 标头值的字符串表示形式。

注意

如果要升级您指定的 SOAP 标头值,BizTalk 项目中必须有与您要升级的值对应的已部署属性架构。

注意

升级后的属性不得超过 256 个字符。

以下 XML 数据显示了 InboundHeaders 属性的 SOAP 标头的字符串表示形式示例。 这来自客户端,并将发送到 BizTalk 接收位置。

<headers>
<a:Action s:mustUnderstand="1" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">Operation_1</a:Action>
<SalesAgent xmlns="Microsoft.Samples.BizTalk.WCF.CustomSoapHeaderPipeline">Contoso</SalesAgent>
<a:MessageID xmlns:a="http://www.w3.org/2005/08/addressing">urn:uuid:26e6720f-5a82-4ef2-b597-6ef077bab92e</a:MessageID>
<a:ReplyTo xmlns:a="http://www.w3.org/2005/08/addressing"><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>
<a:To s:mustUnderstand="1" xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">net.tcp://localhost:9990/NetTcpOrderProcess</a:To>
</headers>

若要将 SOAP 标头值写入或升级到 BizTalk 消息上下文,需要将由属性名称和命名空间组成的值对的集合放入 WCF 消息中,这样 WCF 适配器就可以知道将写入或升级这些标头值。 在将 SOAP 标头值写入或升级到 BizTalk 消息上下文时,WCF 适配器需要获取 WCF 消息中的以下消息属性:

  • 为了将 SOAP 标头值提升到 BizTalk 消息上下文,WCF 适配器将查找键 http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote 和值 List<KeyValuePair<XmlQualifiedName 对象>>对。

    使用对,WCF 适配器从 XmlQualifiedName 对象中获取命名空间、名称和值,并使用它们来提升标头值。

  • 为了写入但不将 SOAP 标头值提升到 BizTalk 消息上下文,WCF 适配器将查找键 http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/WriteToContext 和值 List<KeyValuePair<XmlQualifiedName 对象>>对。

    WCF 适配器使用此对将这些值写入消息上下文。

    以下代码显示的是如何将 SOAP 标头值写入或升级到 BizTalk 消息上下文:

const string PropertiesToPromoteKey="http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/Promote";
const string PropertiesToWriteKey="http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties/WriteToContext";

XmlQualifiedName PropName1=new XmlQualifiedName("Destination", "http://tempuri.org/2007/sample-properties");
XmlQualifiedName PropName2=new XmlQualifiedName("Source", "http://tempuri.org/2007/sample-properties");

//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"));
wcfMessage.Properties[PropertiesToPromoteKey]=promoteProps;

//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"));
wcfMessage.Properties[PropertiesToWriteKey]=writeProps;

BizTalk WCF 服务发布向导未将自定义 SOAP 标头定义包含在生成的元数据中。 若要使用自定义 SOAP 标头发布 WCF 服务的元数据,应手动创建 Web Services 描述语言 (WSDL) 文件。 可以在向导生成的 Web.config 文件中使用 serviceMetadata 元素的 externalMetadataLocation> 属性<来指定 WSDL 文件的位置。 会向用户返回该 WSDL 文件以响应 WSDL 和元数据交换 (MEX) 请求,而不是返回自动生成的 WSDL。

以下 XML 数据显示的示例是定义自定义 SOAP 标头的 WSDL 文件的一部分:

<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:input>
   <wsdl:output name="OrderConfirmation">
     <soap12:header message="i0:OrderConfirmation_Headers" part="PaymentAgent" use="literal" />
     <soap12:body use="literal" />
   </wsdl:output>
</wsdl:operation>

本节内容

另请参阅

WCF 适配器属性架构和属性SOAP 标头与使用的 WCF 服务