我将 WCF 作为 Widnows 服务托管,但在处理 WCF 通道的故障状态时遇到问题。ServiceHost 上的故障事件永远不会出现。
托管应用程序:
protected override void OnStart(string[] args)
{
_serviceHost = new ServiceHost(typeof(WCF_FaultTest.Service1));
_serviceHost.Faulted += _serviceHost_Faulted;
_serviceHost.Open();
}
void _serviceHost_Faulted(object sender, EventArgs e)
{
// never raise up..
}
故障状态我尝试像这样模拟:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
public class Service1 : IService1
{
public string GetFault()
{
throw new Exception("Should went to fault..");
}
我正确使用它吗?谢谢你。