【发布时间】:2016-02-17 21:58:49
【问题描述】:
我正在创建 WCF 服务以接收消息(字符串)。它有肥皂请求有如下所示的标题。我浏览了很多在互联网上找到的示例,但我无法彻底理解其中的任何一个。
我发现这篇文章很有帮助,但仍然无法使用
http://weblogs.asp.net/paolopia/handling-custom-soap-headers-via-wcf-behaviors
看了几篇文章,我知道我需要处理以下区域 (a)SOAP Header (b) Message Inspector (c) Client Context 和 (d) Server Context 类
- 如何处理 mustUnderstand 标头
- 我需要捕获通过
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>
...
【问题讨论】:
-
如果您能够将消息截获为
Message对象,则可以读取Header属性。在这种情况下使用IDispatchMessageInspector。 -
@AmitKumarGhosh 示例代码会有所帮助
-
你好。为什么您需要自定义行为。您是否希望在您的应用程序中针对每个请求进行任何日志记录或审核?
-
我需要能够捕获messageId,我需要能够处理mustunderstand。我仍然无法理解我应该如何完成它。请指教。
-
使用 msdn.microsoft.com/en-us/library/… 实现消息检查器。然后您需要检查
Message.Header以访问发送到服务的内容。
标签: c# wcf soapheader