enf*_*rge 3 c# service wcf timeout
我一直在与WCF进行艰苦的合作。我有一个由控制台应用程序调用的WCF服务(作为Windows服务托管)。效果很好,但是最近我们不得不在10分钟内遇到一个超时问题,当时我们不得不对旧版系统运行查询。
我在服务和客户端.exe中都使用log4net,奇怪的是该服务实际上完成了工作,并且没有引发异常。它运行查询(大约需要12分钟,并创建一个文件并记录成功)。
但是,控制台应用程序记录了一个异常,声称“主机”返回了超时或错误。我认为这是一个超时,而不是缓冲区问题,因为该异常总是在刚开始调用后的第二分钟恰好10分钟发生。
这是我的log4net中的异常/堆栈信息:
2015-07-28 17:35:47,364 [1]
System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:29:59.9843999'. ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:29:59.9843999'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.NegotiateStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
--- End of inner exception stack trace ---
at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.SynchronizedMessageSource.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.Receive(TimeSpan timeout)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceive(TimeSpan timeout, Message& message)
at System.ServiceModel.Dispatcher.DuplexChannelBinder.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 FileGeneratorConsole.FileGeneratorServiceReference.IFileGeneratorService.GenerateXmlFileFromSql(String sqlServer, String sqlDatabase, String sqlQuery, Int32 commandTimeout, Boolean allowEmptyResult, String outputFileName, String xslFileName, Boolean archiveExistingFile)
at FileGeneratorConsole.Program.Main(String[] args)
Run Code Online (Sandbox Code Playgroud)
现在,我以为我已经进行了研究,并弄清楚了可能是什么问题。我以为sendTimeout和receiveTimeout是绑定定义的一部分,所以我添加了:
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IFileGeneratorService"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
receiveTimeout="00:30:00"
closeTimeout="00:30:00"
openTimeout="00:30:00"
sendTimeout="00:30:00">
</binding>
</netTcpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
而且,如果您在上述异常中注意到,您将看到错误提示:
本地套接字超时为“ 00:29:59.9843999”
过去常常说00:09:59 ....所以看起来就这样。
我还将其添加到服务配置文件中,以防万一绑定需要在两面都进行,但这无济于事。
最后,出于绝望,我添加了其他一些内容。我尝试将超时添加到服务部分:
我尝试添加
行为本身。
我现在很茫然,它总是在10分钟后消失。
提前致谢
它总是比您想象的简单。
可悲的是,一直缺少的是service.endpoint中的bindingConfiguration引用。一直以来,该服务一直在使用默认绑定定义运行。我在配置中定义了绑定,但是错过了您指定的部分:
我有:
<endpoint address="" binding="netTcpBinding" bindingConfiguration="">
Run Code Online (Sandbox Code Playgroud)
我需要:
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IFileGeneratorService">
Run Code Online (Sandbox Code Playgroud)
安装好之后,我的实际服务端点正在查看正确的绑定属性。
| 归档时间: |
|
| 查看次数: |
14001 次 |
| 最近记录: |