FaultException和自定义异常WCF
|
我对如何将自定义异常作为FaultException发送有疑问。当我使用诸如ArgumentException之类的系统异常时,它可以工作,但是如果将其更改为自定义异常\“ TestException \”,它将失败。尝试添加服务参考时,无法获取该配置。
作品:
[OperationContract]
[FaultContract(typeof(ArgumentException))]
[TransportChannel TestMethod ();
public Void TestMethod()
{
throw new FaultException<ArgumentException>(new ArgumentException(\"test\"), new FaultReason(\"test\"));
}
不起作用:
[OperationContract]
[FaultContract(typeof(TestException))]
[TransportChannel TestMethod ();
public Void TestMethod()
{
throw new FaultException<TestException>(new TestException(\"test\"), new FaultReason(\"test\"));
}
我的“ TestException”看起来像这样:
[Serializable()]
public class TestException: Exception
{
public TestException () : base() { }
public TestException (string message) : base(message) { }
public TestException (string message, Exception innerException) : base(message, innerException) { }
public TestException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
我猜想我必须在自定义对象上添加DataContract,但是我不明白为什么它不能按原样工作,因为ArgumentException有效。有人可以启发我吗?
感谢帮助 :)
没有找到相关结果
已邀请:
2 个回复
茶鬼失形
眠皇