2012-02-02 92 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