Summary:
FaultExceptionsdon’t fault the channel. All other unhandled exceptions fault the channel. It doesn’t matter what is there in theFaultContract, or if there is even one.- When you are doing development, set
includeExceptionDetailInFaultsequal totrueon server. On client catchFaultException<ExceptionDetail> e. All the information (e.g., stack trace on server) can be obtained by examininge.Detail. - In production, you will set
includeExceptionDetailInFaultsequal tofalse. - If service throws a
FaultException<T>, it will reach the client as aFaultException<T>no matter what is there in the contract. However, if the service does not apply aFaultContract(typeof(T))attribute to the service method, client has no way of knowing that aFaultException<T>can occur.Tcan be anything that WCF can serialize. - All unhandled exceptions translate into a
FaultExceptionon client. - Say you apply a
FaultContract(typeof(DivideByZeroException))and your method throws aDivideByZeroException. Client gets aFaultException. If you want the client to get aFaultException<DivideByZeroException>you have two options:- catch the
DivideByZeroExceptionand instead throw aFaultException<DivideByZeroException>. - use Juwal Lowy’s
PromoteExceptionhelper method in hisServiceModelExlibrary to automagically transform the returned SOAP message so that client in fact gets aFaultException<DivideByZeroException>.
- catch the