Throwing FaultException<T> from WCF service methods

lysergic-acid picture lysergic-acid · Aug 13, 2012 · Viewed 8.4k times · Source

I am learning WCF, and currently focusing on the Faults chapter.

As i understand, WCF handles FaultException exceptions a bit differently when thrown by a service.

As such, it seems like a good idea that all exceptions that are thrown from a service should be wrapped into a FaultException.

Design wise it seems a bit counter-intuitive for me with respect to the design that WCF seems to favor (a clean separation between the actual logic and the "service" configuration/hosting/service-like details).

Is this a good practice then? or is there any other technique that should be used?

Answer

podiluska picture podiluska · Aug 13, 2012

It is common practice to set up a FaultContract on your WCF service, which defines how it is has failed, and then handle this at the client side.

http://msdn.microsoft.com/en-us/library/ms733721.aspx

http://blogs.msdn.com/b/endpoint/archive/2011/01/14/wcf-spike-faultcontract-faultexception-lt-tdetail-gt-and-validation.aspx