如您所知,使用标准WCF服务的FaultException来建议处理异常以隐藏异常详细信息.这没关系,但我遇到了WCF Ria服务的问题.我想从域服务抛出异常,客户端将处理该异常.我想避免泄露异常的敏感信息,如堆栈跟踪,方法名称等.如果它是标准的WCF服务,我会使用FaultException异常,但在Ria服务中,它不起作用.无论我从域服务抛出什么样的异常,客户端总是会收到DomainOperationException.有没有办法可以从域服务向Silverlight客户端抛出FaultException(不透露实际的异常细节)?例如,我有一个登录窗口.当用户点击登录按钮时,应该有几个验证失败,例如:
我希望每个可能发生的错误都有错误类型.客户端应该检查出错的地方并相应地显示错误消息.我禁用了customErrors但它没有帮助.任何帮助,将不胜感激.谢谢
我有一个关于如何发送自定义异常作为FaultException的问题.当我使用像ArgumentException这样的系统异常时,它可以工作,但是如果我将它更改为我的自定义异常"TestException",它就会失败.当我尝试添加它时,我无法获得服务引用的配置.
作品:
[OperationContract]
[FaultContract(typeof(ArgumentException))]
[TransportChannel TestMethod ();
public Void TestMethod()
{
throw new FaultException<ArgumentException>(new ArgumentException("test"), new FaultReason("test"));
}
Run Code Online (Sandbox Code Playgroud)
不起作用:
[OperationContract]
[FaultContract(typeof(TestException))]
[TransportChannel TestMethod ();
public Void TestMethod()
{
throw new FaultException<TestException>(new TestException("test"), new FaultReason("test"));
}
Run Code Online (Sandbox Code Playgroud)
我的"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) { }
} …Run Code Online (Sandbox Code Playgroud) wcf exception-handling exception custom-exceptions faultexception