2012-02-02 74 views
1

我想知道如何在发送错误的WCF请求时WCF返回错误之前捕获异常(日志请求url)。在WCF终止客户端请求之前挂钩到WCF

例如,我使用Fiddler使用以下一个错误的操作元件来发布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> 

请注意,当我使用小提琴手,实际请求的URL可以是不同的,从一个用要的元素。

回答

1

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

+0

感谢您的意见。我会尝试并更新我的结果。 – Pingpong 2012-02-02 17:27:52