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?
Fault exceptions are exceptions that are thrown by a WCF service when an exception occurs at runtime -- such exceptions are typically used to transmit untyped fault data to the service consumers.
We can use FaultException &/or FaultContract (in System. ServiceModel namespace) to these exception details to the client.
In a service, use the FaultException class to create an untyped fault to return to the client for debugging purposes. In a client, catch FaultException objects to handle unknown or generic faults, such as those returned by a service with the IncludeExceptionDetailInFaults property set to true .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With