カスタム例外を 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 が機能するため、そのままでは機能しない理由がわかりません。誰かが私を啓発できますか?
手伝ってくれてありがとう :)