服务OnShutDown()期间的WCF调用

本文关键字:WCF 调用 OnShutDown 服务 | 更新日期: 2023-09-27 18:28:52

我知道这个话题上还有其他一些类似的问题,但似乎没有一个答案,所以我想我们都可以在这里讨论一下。

我的服务器上运行着一个WCF服务,当服务器关闭时,我试图通过重写"OnShutDown()"来发送状态消息。

这可以看出如下:

     protected override void OnShutdown()
           {
               try
               {
                   client.updateInvStatus(machineName, "Client Host Has Shutdown");
               }
               catch (Exception ex)
               {
                   EH.writeToErrorLog("||OnShutdown||Error Shutting Down System 'r'n" + ex);
               }
               base.OnShutdown();
           }

这似乎在50%的时间内有效,另外50%我得到以下错误:

System.ServiceModel.Security.SecurityNegotiationException: Could not establish secure         channel for SSL/TLS with authority '"ENDPOINT ADDRESS REMOVED'. --->     System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.GetResponse()
   at    System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitF orReply(TimeSpan timeout)
 --- End of inner exception stack trace ---
Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebExceptoon webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Ascertain.AscertainAgent.IService.updateInvStatus(String hostNM, String invValue)
   at Ascertain.AscertainAgent.ServiceClient.updateInvStatus(String hostNM, String invValue) in C:'Users'daladd'Documents'CS'Ascertain'Ascertain'Ascertain'Service References'AscertainAgent'Reference.cs:line 209
   at Ascertain.Service1.OnShutdown() in       "FILE LOCATION REMOVED"'Service1.cs:line224

有人知道为什么会发生这种情况吗?

服务OnShutDown()期间的WCF调用

我最终听从了威利博士的话。我为我的连接添加了一个保持活动,现在代码每次都能工作。基本上,在OnShutDown()方法期间,windows不会打开任何新的连接,因此如果连接超时,它将无法正常工作。

如果有人对此有想法的话,那仍然是令人惊讶的,因为使用这种方法,我将有2000个到中央服务器的持久连接。Shiraz,我确实尝试过更改注册表项以允许更长的超时时间,但时间并没有成为问题。

这可能与关闭时间有关。如果关闭时间过长,进程将被终止。这可能发生在你身上。

尝试在此处增加超时:

HKEY_LOCAL_MACHINE''SYSTEM''CurrentControlSet''Control''WaitToKillServiceTimeout

事件日志中可能有一个事件表明进程已终止。