Web Service C#SelfHosted暂时不会响应 [英] Web Service C# SelfHosted does not respnds from a while

查看:110
本文介绍了Web Service C#SelfHosted暂时不会响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我有一个Web服务,该服务是自托管的,并作为Windows Service部署在Windows 2008 R2 OS上.问题是一段时间后,服务主机停止响应.
我们添加了一些日志来跟踪诸如Closed o Faulted之类的事件,我看到我们在处理服务主机关闭的方法中添加的日志

I have a web service which is self hosted and deployed as a windows service on a windows 2008 R2 OS.The problem is that after a while the service host stop responding.
We add some logs to track events like on Closed o Faulted and I see the logs we added in the method that handle the shutting of the servicehost

protected void StartWCFService()
		{
			//Check if the ServiceHost isn't already open
			if (serviceHost != null)
			{
				//if it's true, close it
				serviceHost.Close();
				serviceHost = null;
                LOGGER.Info("StopWCFService stop before start");
			}

			//Create the ServiceHost
			serviceHost = new ServiceHost(typeof(DeviceServiceHost));

            serviceHost.Faulted += new EventHandler(handleWSErrorFault);
            serviceHost.Closed += new EventHandler(handleWSErrorClosed);
            

            // Handle the UnknownMessageReceived event.
            serviceHost.UnknownMessageReceived += delegate(object sender, UnknownMessageReceivedEventArgs e)
            {
                LOGGER.Fatal("Windows Service host unknownMessageReceived. " + e.ToString() + " sender: " + sender.ToString());
            };

            LOGGER.Info("StartWCFService");
			//Open the ServiceHost
			serviceHost.Open();
            LOGGER.Info("Service host has been started");
            this.EventLog.WriteEntry("ServiceHost is ready to receive requests.", EventLogEntryType.Information, 0, 0);
}

void handleWSErrorFault(object sender, EventArgs e)
        {
            this.EventLog.WriteEntry("ServiceHost has faulted.",EventLogEntryType.Error, 0, 0);
            LOGGER.Fatal("DeviceServiceHost Windows Service host faulted. " + e.ToString() + " sender: " + sender.ToString());
            serviceHost.Abort();
            serviceHost.Faulted -= new EventHandler(handleWSErrorFault);
            serviceHost.Closed -= new EventHandler(handleWSErrorClosed);
            this.StartWCFService();
        }

        void handleWSErrorClosed(object sender, EventArgs e)
        {
          
            this.EventLog.WriteEntry("TT Monitor ServiceHost has faulted.", EventLogEntryType.Error, 0, 0);
            LOGGER.Fatal("Windows Service host closed. " + e.ToString() + " sender: " + sender.ToString());
            serviceHost.Abort();
            serviceHost.Faulted -= new EventHandler(handleWSErrorFault);
            serviceHost.Closed -= new EventHandler(handleWSErrorClosed);
            this.StartWCFService();
        }

		/// <summary>
		/// Stop the WCF Service Host
		/// </summary>
		protected void StopWCFService()
		{
            try
            {
                if (serviceHost != null)
                {
                    serviceHost.Close();
                    serviceHost = null;
                    LOGGER.Info("StopWCFService stop");
                    this.EventLog.WriteEntry("ServiceHost has been closed.",EventLogEntryType.Information, 0, 0);
                }
            }
            catch
            {
                this.EventLog.WriteEntry("Error occurs when closing  Service host");
            }
            finally
            {
                serviceHost = null;
            }
}


但是我们所做的只是绕过而已,我们不知道此行为的根本原因是什么

But what we have done is just a bypass and we don't know what is the root cause of this behavior

我有几个问题:

  • 什么可以使停止服务主机?我考虑过ServiceThrottling,我们增加了maxConcurrent ...属性的数量,但是问题仍然存在,而且我无法找到当前数量的电话,会话等...
  • 是否有办法记录导致服务主机的根本原因?
  • 是否可以通过编程方式记录当前会话(呼叫)的数量?
  • What can make stop a servicehost ? I thought about ServiceThrottling and we increase number of maxConcurrent... properties but the problem still occurs and I'm not sur to find the number of current number calls, sessions etc ...
  • is there a way to log the root cause that makes the service host ?
  • Is it possible to log programmatically the number of current sessions, calls ?

P.S.

操作系统:Windows Server 2008

OS: windows server 2008

.NET版本:3.5

.NET Release: 3.5

致谢



推荐答案


这篇关于Web Service C#SelfHosted暂时不会响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆