【问题标题】:Handling custom soap header in WCF Service处理 WCF 服务中的自定义肥皂标头
【发布时间】: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 类

  1. 如何处理 mustUnderstand 标头
  2. 我需要捕获通过messageidReplyToToFromAction 传递的值

需要消费下面的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


【解决方案1】:

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

这些是一些有用的链接:

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

How to use IDispatchMessageInspector in a WCF Service?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-12
    • 1970-01-01
    • 2012-01-03
    • 2010-12-30
    • 1970-01-01
    • 2011-02-01
    • 2012-06-28
    • 2011-01-09
    相关资源
    最近更新 更多