Question

I want my WCF service to be able to return some known faults. ie a defined FaultContract

I'm a bit confused as to whether I should be deriving my own FaultException subclass, or creating a detail class and using FaultException<TDetail>.

There appear to be examples of both scattered about and I just wondered what the general consensus was.

I'm leaning towards deriving, since I think that client code would look cleaner catching MyException rather than WCF centric FaultException<MyExceptionDetail>, but I don't really have any strong feelings about it.

Was it helpful?

Solution

You should use FaultException generally for unknown or generic faults, and FaultException<T> for typed faults.

Typed faults are more akin to typed exceptions in standard .NET, so they would be the preferred method.

Note that you need to use fault contracts in your service contract definition, otherwise all exceptions will reach the client as FaultException, even if you throw a FaultException<T>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top