WCF EntLib 验证 - 更改默认 SOAP 故障原因文本 [英] WCF EntLib Validation - change default SOAP Fault Reason text
问题描述
我正在使用 企业库验证应用程序块我的 WCF 服务.一切都很好,.Net 消费者可以捕获 FaultException
异常以获取人类可读的业务错误集合.但是,对于非 .Net 消费者,尤其是那些将查看原始 SOAP 消息的消费者来说,它看起来并不是那么好.SOAP 原因文本始终是此故障的创建者未指定原因."这不是很有帮助,因为有 原因,它在
元素,如下面的故障消息示例所示.
I'm using the Enterprise Library Validation Application Block for my WCF service. All is fine, and .Net consumers can catch the FaultException<ValidationFault>
exception to get a collection of human-readable business errors. However, it doesn't look quite as great for non-.Net consumers, especially those that are going to be looking at the raw SOAP message. The SOAP Reason text is always "The creator of this fault did not specify a Reason." This isn't very helpful, as there is a reason, it's specified under the <Detail>
element, as shown in the example Fault message below.
有什么方法可以将文本此故障的创建者未指定原因."更改为诸如查看 ValidationFault 详细信息"之类的更有用的内容?
Is there any way to change the text "The creator of this fault did not specify a Reason." to something more helpful like "See ValidationFault Details"?
<s:Body>
<s:Fault>
<s:Code>
<s:Value>s:Sender</s:Value>
</s:Code>
<s:Reason>
<s:Text xml:lang="en-GB">The creator of this fault did not specify a Reason.</s:Text>
</s:Reason>
<s:Detail>
<ValidationFault xmlns="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Details xmlns:b="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF">
<b:ValidationDetail>
<b:Key i:nil="true"/>
<b:Message>Value Validator</b:Message>
<b:Tag>request</b:Tag>
</b:ValidationDetail>
</Details>
</ValidationFault>
</s:Detail>
</s:Fault>
</s:Body>
推荐答案
嗯,EntLib 的人似乎没有想到这个.我已经注意到 EntLib 代码中需要更改的位置并提出了一个 问题在他们的 CodePlex 站点.我想这也可以由任何人作为 EntLibContrib 项目的一部分来完成,但他们似乎仍在企业库 3.1,而我使用的是 4.1.
Well, it seems like the EntLib people didn't think of this one. I've noted where the change in the EntLib code needs to be and raised an issue at their CodePlex site. I guess this could also be done by anyone as part of the EntLibContrib project, but they seem to still be on Enterprise Library 3.1, whereas I'm using 4.1.
我想如果有人不顾一切,解决方案是下载 EntLib 源代码,并修改 ValidationParameterInspector
类中的 BeforeCall
方法(在 Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF
命名空间).这是创建 FaultException
的地方.此构造函数的重载可以指定 FaultReason
.
I guess if anyone's desperate, the solution would be to download the EntLib source code, and modify the BeforeCall
method in the ValidationParameterInspector
class (in the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF
namespace). This is where the FaultException
is created. An overload to this constructor can specify the FaultReason
.
这篇关于WCF EntLib 验证 - 更改默认 SOAP 故障原因文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!