Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何查找ServiceHost故障事件的原因_C#_Wcf_Windows Services_Servicehost - Fatal编程技术网

C# 如何查找ServiceHost故障事件的原因

C# 如何查找ServiceHost故障事件的原因,c#,wcf,windows-services,servicehost,C#,Wcf,Windows Services,Servicehost,我有一个从ServiceBase继承的MyServiceBase类。在MyService中,我为我的WCF服务提供了一个ServiceHost,它只有一个具有IsOneWay=true属性的方法。我使用以下代码对其进行初始化: host = new ServiceHost(typeof(MyService)); host.Opened += new EventHandler(host_Opened); host.Closed += new EventHandler(host_Closed); h

我有一个从ServiceBase继承的MyServiceBase类。在MyService中,我为我的WCF服务提供了一个ServiceHost,它只有一个具有IsOneWay=true属性的方法。我使用以下代码对其进行初始化:

host = new ServiceHost(typeof(MyService));
host.Opened += new EventHandler(host_Opened);
host.Closed += new EventHandler(host_Closed);
host.Faulted += new EventHandler(host_Faulted);
host.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(host_UnknownMessageReceived);
host.Open();
host=新服务主机(typeof(MyService));
host.Opened+=新的事件处理程序(host\u已打开);
host.Closed+=新的事件处理程序(host\u Closed);
host.Faulted+=新的EventHandler(host\u Faulted);
host.UnknownMessageReceived+=新事件处理程序(host_UnknownMessageReceived);
host.Open();
有时主机会引发错误事件,但*host\u Faulted*方法中的EventArgs总是空的,所以我无法找到它的原因。 请帮忙。
感谢您的关注。

此链接对于更好地处理和调试WCF故障非常有用:


因此,我不是在回答您的具体问题,而是推荐一种更好的方法来满足您的要求。

我今天遇到了这个问题。通过启用WCF跟踪,它有所帮助,但没有给出原因。经过大量的调试工作,我发现真正的原因是:使用WCF服务的客户端崩溃了。因为客户端是包装的Windows服务,并且其状态仍然是“正在运行”


因此,我的建议是:尝试/捕获客户端应用程序中的所有代码块

我尝试过使用pseudovariables(),但在本地窗口中没有看到$exception变量。别忘了在主机实现中留下一个无参数构造函数谢谢。这个链接帮了我很多忙。这很有帮助,但没有回答实际问题。如何获取导致服务出错的异常堆栈?