WCF Actions IErrorHandler.ProvideFault ()

My service methods are tagged PrincipalPermissionAttribute , and I have a special IErrorHandler implementation attached to this service. When an incoming request is not authorized to execute the System.Security.SecurityException method. IErrorHandler.ProvideFault() then fired, and I want to specify a special error. But the error parameter is not the original exception; it did not FaultException . Also, error.InnerException is null, even though I have the following setting in config:

 <serviceDebug includeExceptionDetailInFaults="true"/> 

Why? How can I achieve the desired behavior?

+4
source share
1 answer

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

SecurityException refers to CAS (Code Access Security), and this is a fatal exception. Since this exception does not apply to any service exception model, it cannot be an IErrorHandler.

So, I ended up creating an additional class that methods (called methods of the class that implements the service interface) are marked with PrincipalPermissionAttribute and a handler with try / catch.

+1
source

All Articles