什么样的130秒超时终止了我的WCF流媒体服务呼叫?

什么样的130秒超时终止了我的WCF流媒体服务呼叫?,wcf,iis-7,.net-4.0,streaming,basichttpbinding,Wcf,Iis 7,.net 4.0,Streaming,Basichttpbinding,就在最近,我开始研究WCF流的一个棘手问题,在这个问题中,如果客户端在发送到服务器之间等待的时间超过130秒,就会产生CommunicationException 以下是完全例外: System.ServiceModel.CommunicationException was unhandled by user code HResult=-2146233087 Message=The socket connection was aborted. This could be caused b

就在最近,我开始研究WCF流的一个棘手问题,在这个问题中,如果客户端在发送到服务器之间等待的时间超过130秒,就会产生CommunicationException

以下是完全例外:

System.ServiceModel.CommunicationException was unhandled by user code
  HResult=-2146233087
  Message=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 '23:59:59.9110000'.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.WebRequestOutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count)
       at System.Xml.XmlStreamNodeWriter.FlushBuffer()
       at System.Xml.XmlStreamNodeWriter.GetBuffer(Int32 count, Int32& offset)
       at System.Xml.XmlUTF8NodeWriter.InternalWriteBase64Text(Byte[] buffer, Int32 offset, Int32 count)
       at System.Xml.XmlBaseWriter.WriteBase64(Byte[] buffer, Int32 offset, Int32 count)
       at System.Xml.XmlDictionaryWriter.WriteValue(IStreamProvider value)
       at System.ServiceModel.Dispatcher.StreamFormatter.Serialize(XmlDictionaryWriter writer, Object[] parameters, Object returnValue)
       at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Stream stream)
       at System.ServiceModel.Channels.HttpOutput.WriteStreamedMessage(TimeSpan timeout)
       at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.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 WcfService.IStreamingService.SendStream(MyStreamUpRequest request)
       at Client.Program.<Main>b__0() in c:\Users\jpierson\Documents\Visual Studio 2012\Projects\WcfStreamingTest\Client\Program.cs:line 44
       at System.Threading.Tasks.Task.Execute()
  InnerException: System.IO.IOException
       HResult=-2146232800
       Message=Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
       Source=System
       StackTrace:
            at System.Net.Sockets.NetworkStream.MultipleWrite(BufferOffsetSize[] buffers)
            at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
            at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)
            at System.ServiceModel.Channels.BytesReadPositionStream.Write(Byte[] buffer, Int32 offset, Int32 count)
            at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.WebRequestOutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       InnerException: System.Net.Sockets.SocketException
            HResult=-2147467259
            Message=An existing connection was forcibly closed by the remote host
            Source=System
            ErrorCode=10054
            NativeErrorCode=10054
            StackTrace:
                 at System.Net.Sockets.Socket.MultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags)
                 at System.Net.Sockets.NetworkStream.MultipleWrite(BufferOffsetSize[] buffers)
            InnerException: 
为了回应wals的想法,尝试看看我是否通过自托管服务获得了任何不同的结果,我想补充一点,我这样做了,并发现我获得了与在IIS中托管时相同的结果。这是什么意思?我的猜测是,这意味着问题要么在WCF中,要么在Windows的底层网络基础设施中。我使用的是64位Windows 7,通过在Windows 2008服务器上运行各种客户端和服务部分,我们发现了这个问题

更新2013-01-15 当我意识到WCF在Windows7的自托管场景中使用HTTP.sys时,我发现了一些新的线索,这要感谢DarkWanderer。这让我了解了我可以为HTTP.sys配置什么,以及人们报告的HTTP.sys问题类型,这些问题听起来与我正在经历的类似。这使我找到了一个位于C:\Windows\System32\LogFiles\HTTPERR\httperr1.log的日志文件,它似乎记录了HTTP.sys部分的特定类型的HTTP问题。在这个日志中,我每次运行测试时都会看到以下类型的日志条目

2013-01-15 17:17:12 127.0.0.1 59111 127.0.0.1 52733 HTTP/1.1 POST /StreamingService.svc--计时器实体-

因此,关键在于找出哪些条件可能导致错误,以及IIS7或其他地方的哪些设置可能影响错误发生的时间和情况

从:

连接在请求实体主体到达之前过期。当它 如果请求有一个实体体,HTTP API就会打开 定时器\实体定时器。最初,此计时器的限制设置为 connectionTimeout值。每次显示另一个数据指示时 收到此请求时,HTTP API将重置计时器以提供 连接时间超过connectionTimeout中指定的分钟数 属性

在IIS Express的applicationhost.config中,尝试按照上面的引用建议修改connectionTimeout属性似乎没有任何区别。也许IIS Express会忽略此配置并在内部使用硬编码值?我自己尝试了一些东西,发现添加了一些新的netshhttp命令来显示和添加超时值,所以我提出了下面的命令,但不幸的是,这样做似乎对这个错误也没有任何影响

netsh http add timeout timeouttype=IdleConnectionTimeout值=300


可能很遥远,但是。。。检查IIS应用程序池是否已启用Ping。它处于高级设置、流程模型分组中。

从错误判断:

套接字连接已中止。这可能是由错误引起的 正在处理您的消息,或接收超时被 远程主机或底层网络资源问题。本地插座 超时时间为“23:59:59.9110000”

看起来这是一个简单的TCP超时

您可以通过以自托管方式运行应用程序,然后在控制台中运行以下命令来验证它:

netstat -no |find "xxxxx"
其中xxxxx是服务器进程的PID。此命令将显示服务器已建立的连接,并每秒刷新一次

尝试与客户机连接,看看会发生什么。最有可能的情况是,在大约100-120秒后,您会在连接上看到“CLOSE_WAIT”或“TIME_WAIT”,这意味着它由于超时而被中止

可以通过将以下内容添加到配置中来解决此问题:

<httpTransport maxBufferSize="65536"                        
             maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647"
             transferMode="Streamed"
             keepAliveEnabled="true" /> <!-- Here -->


对参数进行了解释

结果表明,此问题是由HTTP.sys使用的值引起的,可以通过IIS管理器通过单个站点的高级设置指定该值。默认情况下,此值配置为在120秒内未收到标头和正文时超时连接。如果接收到来自主体的数据脉冲,则服务器在超时值内重新启动计时器(timer\u EntityBody),然后重置计时器以等待其他数据

这与Timer\u EntityBodyconnectionTimeout指定的值一样,但是很难确定,因为IIS Express似乎忽略了applicationhost.config中limits元素中指定的connectionTimeout值,而不管文档中怎么说。为了确定这一点,我必须在我的开发机器上安装完整版本的IIS,并在托管我的站点后修改上述设置


由于我们在Windows 2008上的IIS下托管真正的服务,上述解决方案将对我有效,但问题仍然在于如何在您自托管的情况下正确修改连接超时值。

试试这个,对我来说它解决了问题。问题是底层内核http.sys有自己的超时,它会中断连接

http://mmmreddy.wordpress.com/2013/07/11/wcf-use-of-http-transport-sharing-persistent-tcp-sessions/

netsh http add timeout timeouttype=idleconnectiontimeout value=120
你考虑过了吗?

我在我的ISAPI扩展中观察到这样的流中断。关机后
在IIS 7中进行缓冲根据此支持说明,一切正常。

我们将需要您的app.config文件(两侧)@wal-此时配置文件没有意思。我在一个简单的测试应用程序中复制了这一点,但为了满足请求,我将更新我的帖子。这是接收超时2分钟还是2小时?:)尝试将其更改为最大值:
24.20:31:23.6470000
ok。您是否可以尝试删除客户端和服务器端绑定的赋值,看看是否有差异?(可能无法解决问题,但可能会缩小范围)。另外,您可以单独运行WCF服务(它自己的进程)来排除一些问题吗?我研究了这一点,不幸的是,我现在正在IIS Express上复制这一点,并在applicationhost.config onl中设置pingFrequency值
<httpTransport maxBufferSize="65536"                        
             maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647"
             transferMode="Streamed"
             keepAliveEnabled="true" /> <!-- Here -->
http://mmmreddy.wordpress.com/2013/07/11/wcf-use-of-http-transport-sharing-persistent-tcp-sessions/

netsh http add timeout timeouttype=idleconnectiontimeout value=120