views:

258

answers:

2

We have a system with a WCF layer.

The WCF services can throw various FaultExceptions, these are exceptions of type:

FaultException<MyStronglyTypedException>

All strongly types exceptions inherit from a base exception.

public class MyStronglyTypedException : MyBaseException

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

What I would like to catch is:

FaultException<MyBaseException>

But this does not seem to be possible.

Is there a way that I can get access to the Detail property of the FaultException, without catching every individual strongly typed exception?

+1  A: 

Don't have a tried and tested answer for you but this link may be of use:

Exception Handling in WCF using Fault Contract

Tanner
Thanks, but this is what we are currently doing, where he has:catch (FaultException<IndigoClient.localhost.MyFaultException> ee)We have over 100 different exceptions, currently I have written a program to generate this code.
Shiraz Bhaiji
+3  A: 

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

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

If you don't "declare" those specific types which you want to catch strongly typed FaultContract<T> exceptions for, WCF will convert all server side faults into general-purpose FaultContract instances.

marc_s