wcferror-handlingierrorhandler

WCF IErrorHandler.ProvideFault() behavior


My service methods are marked with PrincipalPermissionAttribute and i have a custom IErrorHandler implementation attached to the service. When an incoming request has no permissions to execute the method System.Security.SecurityException is thrown. IErrorHandler.ProvideFault() is then triggered and i want to provide a special fault. But error parameter is not original exception, it's untyped FaultException. Moreover, error.InnerException is null despite i have the following setting in the config:

<serviceDebug includeExceptionDetailInFaults="true"/>

Why? How can i achieve the desired behavior?


Solution

  • According to this SecurityException is kind of "special" for WCF:

    SecurityException is related to CAS (Code Access Security), and it is a fatal exception. Since this exception is not related to any service model exceptions, it cannot be handled by IErrorHandler.

    So i ended up by creating additional class which methods (called from the methods of the class implementing the service interface) are marked with PrincipalPermissionAttribute and a handler function with try/catch.