Search code examples
.netwcfexceptionfault

WCF: which kind of exception to handle


In WCF service, I will have exception happening.

I've the IncludeExceptionDetailInFaults attribute in the serviceDebug behavior.

if I've a method declared like this:

[OperationContract]
String SayHello(String name);

And let's imagine that I do something that generate a NullReferenceException in this SayHello method.

On the client side, what will I receive? A FaultException or a NullReferenceException?

I can't find any documentation on this.

Thank you very much


Solution

  • The client should receive a faultexception, always - as its a soap fault... If you want further detail, you can add this to your operation contract: [FaultContract(typeof(NullReferenceException))] and then you can catch it like this:

    }catch(FaultException<NullReferenceException> e){...