gpt4 book ai didi

c# - WCF:套接字连接已中止。远程主机超过接收超时

转载 作者:行者123 更新时间:2023-11-30 14:52:25 26 4
gpt4 key购买 nike

我一直在处理 WCF 的难题。我有一个由控制台应用程序调用的 WCF 服务(作为 Windows 服务托管)。它运行良好,但最近我们在必须对遗留系统运行查询时遇到了 10 分钟的超时问题。

我在服务和客户端 .exe 中都使用了 log4net,奇怪的是服务实际上完成了工作并且没有抛出异常。它运行查询(大约需要 12 分钟,并创建一个文件并记录成功)。

但是,控制台应用程序记录了一个异常,声称“主机”返回了超时或错误。我认为这是超时而不是缓冲区问题,因为异常总是在最初发出调用后恰好 10 分钟后发生。

这是来 self 的 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)

现在,我认为我已经完成了研究并弄清楚了问题所在。我假设它是绑定(bind)定义的一部分的 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>

而且,如果您在上面的异常中注意到,您会看到错误显示:

本地套接字超时为“00:29:59.9843999”

它以前说的是 00:09:59....所以看起来是这样。

我还将此添加到服务配置文件中,以防万一双方都需要绑定(bind),但这没有帮助。

最后,出于绝望,我添加了一些其他的东西。我尝试向服务部分添加超时:

我尝试添加

行为本身。

我现在很茫然,它总是在 10 分钟后死亡。

提前致谢

最佳答案

它总是比您想象的要简单。

遗憾的是,一直缺少的是 service.endpoint 中的 bindingConfiguration 引用。一直以来,该服务都假定使用默认绑定(bind)定义运行。我在我的配置中定义了一个绑定(bind),但错过了您指定的部分:

我有:

 <endpoint address="" binding="netTcpBinding" bindingConfiguration="">

我需要:

 <endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IFileGeneratorService">

一旦到位,我的实际服务端点就会查看正确的绑定(bind)属性。

关于c# - WCF:套接字连接已中止。远程主机超过接收超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31707925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com