Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF:IErrorHandler实现未按指定提供泛型错误_C#_Wcf_Ierrorhandler - Fatal编程技术网

C# WCF:IErrorHandler实现未按指定提供泛型错误

C# WCF:IErrorHandler实现未按指定提供泛型错误,c#,wcf,ierrorhandler,C#,Wcf,Ierrorhandler,我已经实现了IErrorHandler接口的providdefault方法,如下所示: public void ProvideFault(Exception ex, MessageVersion version, ref Message fault) { ResponseModel responseModel = new ResponseModel(); responseModel.EndDate = DateTime.Now; FaultException<Re

我已经实现了
IErrorHandler
接口的
providdefault
方法,如下所示:

public void ProvideFault(Exception ex, MessageVersion version, ref Message fault)
{
    ResponseModel responseModel = new ResponseModel();
    responseModel.EndDate = DateTime.Now;

    FaultException<ResponseModel> faultEx;

    if (ex is FaultException<ResponseModel>)
    {
        return;
    }
    ServerCoreException coreException = ex as ServerCoreException;
    if (coreException != null)
    {
        ServerCoreException serverCoreException = coreException;
        faultEx = new FaultException<ResponseModel>(responseModel,
        new FaultReason(serverCoreException.Message),
        new FaultCode(serverCoreException.ErrorCode.ToString()));
    }
    else
    {
        faultEx = new FaultException<ResponseModel>(responseModel,
        new FaultReason(ex.Message),
        new FaultCode("-1"));
    }
    MessageFault msgFault = faultEx.CreateMessageFault();
    fault = Message.CreateMessage(version, msgFault, faultEx.Action);
}
但是服务实现内部方法的测试总是失败,抱怨接收到的故障不是
FaultException
类型,而是
FaultException

Assert.That(() => client.CreateVersion(request), Throws.TypeOf<FaultException<ResponseModel>>());
Assert.That(()=>client.CreateVersion(请求),抛出.TypeOf());

为什么我在客户端接收到的是
FaultException
而不是
FaultException

可能相关:@ricardopers谢谢,但我的代码fault=Message.CreateMessage中已经有了(版本,msgFault,faultEx.Action);正如被接受的答案中所建议的。ResponseModel[DataContract]应用了吗?@Maximus感谢您的时间。是的,我设置了DataContract属性。
Assert.That(() => client.CreateVersion(request), Throws.TypeOf<FaultException<ResponseModel>>());