投掷的FaultException< T>从WCF服务使“这种故障没有指定一个理性的创造者。” [英] Throwing a FaultException<T> from a WCF services causes 'The creator of this fault did not specify a Reason.'

查看:559
本文介绍了投掷的FaultException< T>从WCF服务使“这种故障没有指定一个理性的创造者。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在扔了的FaultException< CustomFault> 是这样的:

throw new FaultException<CustomFault>(new CustomFault("Custom fault message"));



我得到如下:此故障的创建者未指定原因
现在根据这个MSDN文章一个不需要使用 FaultReason

我有以下的服务合同:

[OperationContract]
[FaultContract(typeof(CustomFault))]
CustomType[] SomeMethod(int someParameter);

[DataContract]
public class CustomFault
{
    private string report;

    public CustomFault(string message)
    {
        this.report = message;
    }

    [DataMember]
    public string Message
    {
        get { return this.report; }
        set { this.report = value; }
    }
}

有上MSDN文章的建议评论它是强制性使用其他 FaultReason ,但在其他几个地方我看到有人争辩说,你不应该使用 FaultReason ,除非必要的。

There is a comment on the MSDN article that suggest it is mandatory to use the other FaultReason, but in several other places I have seen people arguing that you shouldn't use the FaultReason unless necessary.

所以我的问题是如下:是不是真的强制使用 FaultReason 如果没有 - 我该如何防止引发的异常试图抛出时,的FaultException

So my question is as follows; is it really mandatory to use the FaultReason and if not - how can i prevent the exception raised when trying to throw a FaultException?

修改

通过从的this文章我得到excact相同的行为。也许这是在.NET中的文件/样品不被更新。更新造成的。

By running the sample project from this article I get the excact same behavior. Maybe it's caused by an update in .NET an the documentation/samples not being updated.

推荐答案

故障的原因是。要求,而在细节都是可选的

WCF使用的FaultException.Reason 属性来填充< faultstring> 元素在SOAP错误,这是由 SOAP规范:

WCF uses the value of the FaultException.Reason property to populate the <faultstring> element of the SOAP Fault, which is required by the SOAP specification:

faultstring 结果
的faultstring元素旨在提供故障的人类可读的解释,而不是针对算法
处理。 [...] 的IT部门必须在SOAP Fault元素和$ B $乙方应至少提供了一些资料,解释了
故障的性质。

faultstring
The faultstring element is intended to provide a human readable explanation of the fault and is not intended for algorithmic processing. [...] It MUST be present in a SOAP Fault element and SHOULD provide at least some information explaining the nature of the fault.

因此,您必须为故障提供了一个理由投掷的FaultException

这篇关于投掷的FaultException&LT; T&GT;从WCF服务使“这种故障没有指定一个理性的创造者。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆