开发者

WCF IErrorHandler.ProvideFault() behavior

开发者 https://www.devze.com 2023-01-27 10:02 出处:网络
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 met

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 provi开发者_开发知识库de 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号