我想像这样使用custome FaultException
[DataContract]
public class Fault
{
[DataMember]
public string Message { get; set; }
}
public class MyFault<T>:FaultException<T> where T : Fault
{
public MyFault(T faultClass)
: base(faultClass, new FaultReason(faultClass.Message))
{
}
}
...
throw new MyFault<Fault>(new Fault {Message = "hello"});
...
界面
[OperationContract]
[FaultContract(typeof(Fault))]
string GetData2(int value);
但是当它到达客户端时,它会转换为 FaultException
try
{
var res = serv.GetData2(1);
}
catch (MyFault<WcfService1Sample.Fault> ex)
{
label1.Text = ex.Reason.ToString(); //-> i want here
}
catch (FaultException<ServiceReference1.Fault> ex)
{
label1.Text = ex.Reason.ToString(); //-> catch here
}
catch (Exception)
{
throw;
}
我可以在 clint 上发现自定义错误吗?或 WCF 自动将其转换为 FaultException 我如何解决此问题
谢谢 kfir