WCF error handling without fail

I have a WCF service for which all operations return an OperationStatus type:

[DataContract] public abstract class ServiceResponse { [DataMember] public bool Success { get; set; } [DataMember] public String StatusReason { get; set; } } 

I would like to create an ErrorHandler to catch all the exceptions, and then I would like it to return to the client instance of the ServiceReponse class with the Success property set to false and the StatusReason is "INTERNAL SERROR".

At the moment, I have my own class that implements IErrorHandler, but I do not want to use FaultContract - I just want to return to the regular client client of the StatusReason type. It can be done?

+4
source share
3 answers

You need a malfunction contract to send an error message, try the following:

  MyException fault = new MyException("Error message"); throw new FaultException<MyException>(fault, new FaultReason("Reason Text")); 
+3
source

You can add

  <serviceDebug includeExceptionDetailInFaults="true"/> 

In the section of official behavior, but in reality it is not the best for the production environment.

+2
source

All Articles