WCF Fault Trap Type T or Base Type Exceptions

We have a system with a WCF layer.

WCF services can throw various FaultExceptions, these are exceptions like:

FaultException<MyStronglyTypedException> 

All strong exception types are inherited from the base exception.

 public class MyStronglyTypedException : MyBaseException 

I can catch a FaultException, but then I do not have access to the Detail property of the FaultException property.

I would like to catch:

 FaultException<MyBaseException> 

But this is not possible.

Is there a way to access the Detail property from a FaultException without catching every single strongly typed exception?

+6
exception-handling wcf
source share
2 answers

If you want to catch the strongly typed FaultException<MyBaseException> in your client code, you must decorate your service method with the FaultContract attribute for this type:

 [ServiceContract] interface IYourService { [OperationContract] [FaultContract(typeof(MyBaseException))] ResponseType DoSomethingUsefulHere(RequestType request); } 

If you do not β€œdeclare” those specific types that you want to catch the strongly typed FaultContract<T> exceptions, WCF converts all server-side failures into general-purpose FaultContract .

+5
source share

You have no verified answer, but this link may be useful:

WCF Exception Handling Using Error Contract

+1
source share

All Articles