WCF没有明显原因调用超时

时间:2012-11-20 14:20:18

标签: c# sql-server wcf nhibernate

我正在开发一个包含数据库服务的内部软件,该服务用于提供对运行数据库服务的同一服务器上本地SQL Server数据库的访问。

数据库服务是针对.NET 4.0编写的WCF服务,VS 2010是32位应用程序。截至目前,客户端和服务器现在通过交叉电缆相互连接。

数据库服务有两个客户端。一个客户端尝试以4hz存储数据。另一个客户端尝试以1hz存储数据。这通常完全正常,但是偶尔尝试以1hz超时存储数据的客户端。数据库服务是具有多个并发模式的单例服务。 1hz和4hz客户端执行不同的方法,只共享一个nhibernate会话工厂。

为了更好地了解发生了什么,我使用Stopwatch类为1hz客户端的调用添加了一些基本的分析。我发现数据存储的所需数据不到40ms。 4hz客户端将所需数据存储在10ms以内。两个客户端的超时时间均为5秒(双向)。

一个奇怪的是,只有1hz客户端遇到超时问题。 4hz客户端继续工作。另一个是当我在1hz客户端上捕获超时异常并且我在同一时间检查服务器上的日志时,我发现服务器确实执行并存储数据(在40ms内,比5s超时快得多)。为了进一步解决这个问题,似乎在此事件发生后约1分钟,1hz客户端从不尝试存储数据(即使正在生成数据)。我也从未观察到另一个超时异常。然后1hz客户端重新开始并再次开始存储数据,好像什么都没发生过一样。

在此期间,4hz客户端继续运行,好像没有任何问题。 1hz客户端和4hz客户端托管在同一个应用程序中,但在不同的线程上执行。

过去3天我一直在阅读有关WCF超时的潜在原因,并确保遵循我找到的建议。 WCF客户端代理已打开,执行和关闭。 SQL Server调用所花费的时间比5s超时时间少得多。

如果需要代码,我将使用所请求的代码编辑问题。我现在不知道如何继续这样做,所以非常感谢你的帮助。

编辑#1:

客户端的工作方式如下。打开代理。执行Ping()(一个空方法,以确保服务已启动)。执行实际工作方法。关闭代理。堆栈跟踪表明ping工作正常,但是当客户端尝试执行工作方法时,事情进展不顺利。

XXX.XXX.ServiceConnectionException: Failed to connect to service XXX.XXX.IDatabaseService. ---> System.TimeoutException: The request channel timed out attempting to send after 00:00:05. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The HTTP request to 'http://192.168.100.100/database' has exceeded the allotted timeout of 00:00:00. The time allotted to this operation may have been a portion of a longer timeout.
   at System.ServiceModel.Channels.HttpChannelUtilities.SetRequestTimeout(HttpWebRequest request, TimeSpan timeout)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   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 XXX.XXX.IService.Ping()
   at XXX.XXX.Client`1.Open() in C:\XXX\XXX\XXX\XXX\Client.cs:line 76
   --- End of inner exception stack trace ---
   at XXX.XXX.Client`1.Open() in C:\XXX\XXX\XXX\XXX\Client.cs:line 81
   at XXX.XXX.Client`1.Execute(Action`1 execute) in C:\XXX\XXX\XXX\XXX\Client.cs:line 93
   at XXX.XXX.XXX.ProcessItems(List`1 items) in C:\XXX\XXX\XXX\XXX\InsertProcess.cs:line 57

0 个答案:

没有答案