没有故障合同的WCF错误处理 [英] WCF Error Handling without fault contract

查看:80
本文介绍了没有故障合同的WCF错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务,所有操作的返回类型均为OperationStatus:

I have a WCF service which all operations return type is OperationStatus:

[DataContract]
public abstract class ServiceResponse
{
    [DataMember]
    public bool Success { get; set; }

    [DataMember]
    public String StatusReason { get; set; }

}

我想创建一个ErrorHandler来捕获所有异常,然后我希望它返回到ServiceReponse类的客户端实例,并将属性Success设置为false并将StatusReason设置为 INTERNAL SERROR。

I'd like to create an ErrorHandler to catch all exceptions and then I'd like it to return to the client instance of class ServiceReponse with property Success set to false and StatusReason set to "INTERNAL SERROR".

到目前为止,我有自己的类实现IErrorHandler,但我不想使用FaultContract-我只想返回到StatusReason类型的客户端常规对象。可以做到这一点吗?

As for now I have my own class implementing IErrorHandler but i don't wanna use FaultContract - i just want to return to the client regular object of type StatusReason. Can this be done?

推荐答案

您确实需要错误合同,以便发送原因,请尝试以下操作:

You do need a fault contract, in order to send over a Reason, try this:

   MyException fault = new MyException("Error message");
   throw new FaultException<MyException>(fault, new FaultReason("Reason Text"));

这篇关于没有故障合同的WCF错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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