Pingpong
Pingpong

Reputation: 8009

Hook into WCF before WCF terminates client request

I want to find out how to catch exception (log request url) before WCF returns error when a wrong WCF request is sent.

For example, I use Fiddler to post a WCF request using a wrong Action element below:

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

WCF service returns error below to client and terminates the request. How to catch the request url, catch the exception before WCF terminates it.

Exception returned from 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>

Please note that when I use fiddler, the actual request url can be different from one with To element.

Upvotes: 1

Views: 339

Answers (1)

Chandermani
Chandermani

Reputation: 42669

Have a look at IErrorHandler Interface. If configured correctly all exceptions would flow through it. I have not tried it but within the HandleError you can log whatever you want. The OperationContext can give you data that you are looking for. Look at this sample

Upvotes: 1

Related Questions