【发布时间】:2015-05-13 13:25:52
【问题描述】:
我试图通过 WCF 线路发送异常,但无法弄清楚我做错了什么。 我正在关注guidance of Oleg Sych 和MSDN 但无济于事。
我返回的是The requested service, 'net.tcp://mymachine/myservicepath/MyService.svc' could not be activated. See the server's diagnostic trace logs for more information.。
[ServiceContract]
public interface ISystemInfoService
{
[OperationContract]
[FaultContract(typeof(MyException))]
void DoThrowException(string message);
}
//[ServiceContract] // <- the culprit
public class SystemInfoService : ISystemInfoService
{
public void DoThrowException(string message)
{
try
{
throw new MyException( "MyMessage" );
}
catch (MyExceptionexc)
{
throw new FaultException<MyException>(exc);
}
}
}
// The custom Exception resides in an common assembly reachable from both server and client.
[Serializable]
public class MyException: Exception
{
...
}
TIA
【问题讨论】:
-
那么,你
See the server's diagnostic trace logs for more information了吗? -
好发现@nvoigt - 我很惭愧地回答我没有。当我检查事件查看器-> 自定义视图-> 管理事件时,我发现
... Contract inheritance can only be used among interface types. If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute...这显然是罪魁祸首。我已经更新了原始代码以显示这一点。 -
@nvoigt - 请回答有关如何访问“服务器的诊断跟踪日志”的说明,我很乐意为您提供应得的积分。
标签: c# .net wcf exception-handling