【问题标题】:Hook into WCF before WCF terminates client request在 WCF 终止客户端请求之前挂钩到 WCF
【发布时间】:2012-02-02 00:42:48
【问题描述】:

我想了解在发送错误的 WCF 请求时如何在 WCF 返回错误之前捕获异常(日志请求 url)。

例如,我使用 Fiddler 通过以下错误的 Action 元素发布 WCF 请求:

<a:Action s:mustUnderstand="1">http://www.xxx.com/Wrong</a:Action>

WCF 服务向客户端返回以下错误并终止请求。如何捕获请求url,在WCF终止之前捕获异常。

从 WCF 返回的异常:

http://www.w3.org/2005/08/addressing/faulturn:uuid:872ca27f-24c8-4855-8739-e36bd1d921e71e67f1d2-7550-4c41-88cf-acdf8ebd6bd4s:Sendera:ActionNotSupportedThe message with Action 'http://www.xxx.com/Wrong' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).


<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://www.xxx.com/Wrong</a:Action>

    </a:ReplyTo>
    <a:To s:mustUnderstand="1">http://www.xxx.com/Service.svc</a:To>
  </s:Header>
</s:Envelope>

请注意,当我使用 fiddler 时,实际的请求 url 可能与带有 To 元素的不同。

【问题讨论】:

    标签: wcf


    【解决方案1】:

    看看IErrorHandler 接口。如果配置正确,所有异常都会通过它。我没有尝试过,但在 HandleError 中你可以记录任何你想要的。 OperationContext 可以为您提供您正在寻找的数据。看看这个sample

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多