在 WCF 服务中处理自定义肥皂头

问题描述 投票:0回答:2

我正在创建 WCF 服务来接收消息(字符串)。它的肥皂请求具有标头,如下所示。我浏览了在互联网上找到的很多例子,但我无法彻底理解其中的任何一个。

我发现这篇文章非常有帮助,但仍然无法使其发挥作用

http://weblogs.asp.net/paolopia/handling-custom-soap-headers-via-wcf-behaviors

读了几篇文章后,我知道我需要处理以下区域(a)SOAP 标头(b)消息检查器(c)客户端上下文和(d)服务器上下文类

  1. 如何处理 MustUnderstand 标头
  2. 我需要捕获传递的值
    messageid
    ReplyTo
    To
    From
    Action

需要消费以下soap消息

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
    <soapenv:Header>
    <a:Action s:mustUnderstand="1">urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b</a:Action>
    <a:From><a:Address>urn:oid:1.2.3.4.5.6.1234567.10.70.142.2</a:Address>
    </a:From>
    <a:MessageID>urn:uuid:3a40ebfe-2abc-4de9-b6f6-06c7962f6050</a:MessageID>
    <a:ReplyTo>
    <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To>https://localhost/MyWCFService/Service.asmx</a:To>
</soapenv:Header>

...

c# wcf soapheader
2个回答
0
投票

如果您正在创建 WCF 服务并尝试检查 SOAP 消息,则可以实现 IDispatchMessageInspector 接口 另外,对于 WCF 客户端,请参阅 IClientMessageInspector 接口

这些是一些有用的链接:

http://ianpicknell.blogspot.com.tr/2011/03/implementing-idispatchmessageinspector.html

如何在 WCF 服务中使用 IDispatchMessageInspector?


0
投票

要读取 WCF 服务中自定义肥皂标头的值,我可以在服务回调中使用以下内容:

int nSubscriptionIdHeader = Headers.FindHeader("SubscriptionId", CommonNamespaces.LumosManager);
string strSubscriptionId = Headers.GetHeader<string>(nSubscriptionIdHeader);
© www.soinside.com 2019 - 2024. All rights reserved.