【发布时间】:2011-02-03 10:07:30
【问题描述】:
我有这个简单的测试项目只是为了测试 IncludeExceptionDetailInFaults 行为。
public class Service1 : IService1
{
public string GetData(int value)
{
throw new InvalidCastException("test");
return string.Format("You entered: {0}", value);
}
}
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
在服务的 app.config 中,我将其设置为 true
<serviceDebug includeExceptionDetailInFaults="True" />
在客户端:
try
{
using (var proxy = new ServiceReference1.Service1Client())
Console.WriteLine(proxy.GetData(5));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
这就是我认为的行为: 设置为 includeExceptionDetailInFaults=true 会将异常详细信息传播到客户端。但我总是收到 CommunicationObjectFaultException。
我确实尝试在合同上使用 FaultContract(typeof(InvalidCastException)),但行为相同,只得到 CommunicationObjectFaultException。
让它工作的唯一方法是抛出 new FaultException(new InvalidCastException("test"));
但我认为使用 IncludeExceptionDetailInFaults=true 以上是自动完成的。
我错过了什么吗?
【问题讨论】:
标签: c# .net wcf exception-handling