Ensuring WCF Correctly Reports Errors

This is another one of my note to my future self posts, that might be useful to somebody else, so skip past if you don’t know what WCF is…

Anyway, if you’re still here, I’ve spent the past day or so trying to track down a problem in some WCF code. Essentially the problem has been that whilst I have been out of the office over the last week, we’ve had a change propagate through to our development server which has caused problems with some of our existing services, specifically some code where one service needs to make a call to another service running on the same machine to finish it’s work. To do this it needs to pass through the Kerberos ticket that the initial service has received, and whilst up to now it has been quite happily doing this, now it has stopped and instead is getting the credentials for the underlying windows service passed.

The problem was made a lot harder to diagnose by a little WCF gotcha whereby the error that is generated is overwritten when the calling code tries to dispose of the service object. Damien McGivern has an excellent post describing the problem and giving a solution, however it didn’t quite meet our needs, as we sometimes need to specify an endpoint when creating the proxy object.

To get around the problem, I adapted Damien’s code slightly creating an extension method taking an object of type TService rather than creating the object within the method, so the method can be used as follows:

new RelationshipServiceClient().UsingService(service => ... );

Whilst it doesn’t actually solve the mystery of why our server started mishandling WCF calls, it did at least give us a bit more clue!

One thought on “Ensuring WCF Correctly Reports Errors”

Leave a Reply