WCF IErrorHandler.ProvideFault() 行为

标签 wcf error-handling ierrorhandler

我的服务方式标有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/

相关文章:

asp.net - 如何解决Kerberos双跳问题?

.net - System.ServiceModel、可移植类库和代码分析

error-handling - Quartz.net Cron触发器仅触发一次

c# - wcf rest ierrorhandler webfaultexception

c# - WCF 将额外的 HTTP header 添加到 HTTP 响应以传输 SOAP 消息

c# - Entity Framework - 底层提供程序在 ConnectionString 上失败

Angular 4.3 - HTTP 拦截器 - 刷新 JWT token

c++ - OpenCV:grabcut.cpp 错误

没有故障契约的 WCF 错误处理

c# - 如何将对象注入(inject) WCF 的 IErrorHandler?