WCF&企业库-异常屏蔽和验证应用程序块
我有一个 WCF 服务,它使用 Enterprise Library 进行异常处理和 WCF 验证集成。他们似乎不合作。
我想要的是:
- 如果我的服务抛出任何类型的异常,WCF 异常屏蔽将捕获此异常并抛出
FaultException
。 - 如果传入消息未通过验证,服务应继续抛出
FaultException
。
但是,我不知道如何告诉异常屏蔽策略让验证异常通过。
我有一些企业库配置,可将每个异常转换为 FaultException
。如果我让 EnterpriseLibrary 记录它捕获的异常,它会说它得到了
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractWrapperException
。但是,如果将此异常作为新的
添加到配置中,并且 postHandlingAction
为 None
,我仍然会得到 FaultException< ;MyServiceFault>
验证失败时抛出。
是否可以使用 WCF 异常屏蔽来捕获除 WCF 验证异常之外的所有异常?如果没有,我将不得不为可能引发的所有不同异常添加更多配置 - 在这种情况下异常屏蔽的意义何在?
I've got a WCF service that's using Enterprise Library for its Exception Handling and WCF Validation Integration. They don't seem to work together.
What I want is:
- If my service throws any kind of exception, WCF Exception Shielding will catch this and throw out a
FaultException<MyServiceFault>
. - If the incoming message fails the validation, the service should continue to throw out a
FaultException<ValidationFault>
.
However, I don't know how to tell the Exception Shielding policy to let Validation exceptions through.
I have some Enterprise Library config that turns every exception into a FaultException<MyServiceFault>
. If I get EnterpriseLibrary to log the exceptions it catches, it says it gets a
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractWrapperException
when validation fails. But if add this exception to the config as a new <exceptionType>
with a postHandlingAction
of None
, I still get a FaultException<MyServiceFault>
thrown out when validation fails.
Is it possible to use WCF Exception Shielding to catch every exception other than WCF Validation exceptions? If not, I'll have to add tons more config for all the different exceptions that might be thrown - what is the point of exception shielding in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,虽然我以为我已经尝试过这个,但以下配置似乎可以完成这项工作:
服务代码内抛出的任何异常,都会以
FaultException
的形式抛出,除非WCF 验证应用程序块抛出异常,然后一切正常,并且客户端收到FaultException
。Hmm, well although I thought I'd already tried this, the following configuration seems to do the job:
Any exception gets thrown inside the service code, it's thrown out as a
FaultException<MyServiceFault>
, except if the WCF Validation Application Block throws an exception, then everything works as normal and the client receives aFaultException<ValidationFault>
.库中存在一个错误,该错误会阻止您提供的解决方案正常运行。解决方法是不更改异常屏蔽块的默认策略名称。
请参阅此链接对此错误进行投票。
There's a bug in the library that would prevent the solution you provided from functioning. The workaround is not to change the default policy name of the exception shielding block.
Refer to this link to add vote to this bug.