我的服务方式标有PrincipalPermissionAttribute
我有一个自定义 IErrorHandler
附加到服务的实现。当传入的请求无权执行方法System.Security.SecurityException
被抛出。 IErrorHandler.ProvideFault()
然后触发,我想提供一个特殊的故障。但是error
参数不是原始异常,它是无类型的 FaultException
.此外,error.InnerException
尽管我在配置中有以下设置,但为空:
<serviceDebug includeExceptionDetailInFaults="true"/>
为什么?我怎样才能达到预期的行为?
最佳答案
根据this SecurityException
对 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.
所以我最终创建了额外的类,其中方法(从实现服务接口(interface)的类的方法调用)标记为
PrincipalPermissionAttribute
和一个带有 try/catch 的处理函数。
关于WCF IErrorHandler.ProvideFault() 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4293828/