WCF:基础连接已关闭:连接意外关闭

时间:2017-01-31 12:57:32

标签: c# .net windows wcf soap

由于这是一个非常常见的问题,但没有适当的解决方案可以解决这个问题。我也遇到了这个“底层连接已关闭:连接意外关闭”我的WCF Web服务的问题,但它是随机的,没有特定的场景,我可以通过它重现。我已经尝试解决这个问题,因为几个星期并尝试了所有可能的解决方案,包括增加超时,启用/禁用保持连接,为每个请求打开一个新连接,然后在请求完成后立即关闭但是有没运气。我还在服务器端和客户端都启用了跟踪和日志记录,但找不到可能导致此问题的特定问题。

使用IIS 7和.Net Framework 4.0在Windows服务器环境中部署的这些WCF SOAP Web服务

客户端跟踪:

System.Net.Sockets Verbose: 0 : [351180] 00000000 :                                                 : 
    DateTime=2017-01-20T14:25:44.4000839Z
System.Net.Sockets Verbose: 0 : [351180] Exiting Socket#34051556::Receive()     -> Int32#0
    DateTime=2017-01-20T14:25:44.4000839Z
System.Net.Sockets Verbose: 0 : [351180] Socket#34051556::Dispose()
    DateTime=2017-01-20T14:25:44.4000839Z
System.Net Error: 0 : [351180] Exception in HttpWebRequest#40245115:: - The underlying connection was closed: The connection was closed unexpectedly..
    DateTime=2017-01-20T14:25:44.4157088Z
System.Net Error: 0 : [351180] Exception in HttpWebRequest#40245115::GetResponse - The underlying connection was closed: The connection was closed unexpectedly..
    DateTime=2017-01-20T14:25:44.4157088Z

服务器端跟踪:

System.Net.Sockets Verbose: 0 : [10808] Exiting DNS::GetHostByName()    -> IPHostEntry#31978062
    DateTime=2017-01-20T14:16:20.7036270Z
System.Net.Sockets Verbose: 0 : [10808] Exiting DNS::GetHostAddresses()     -> IPAddress[]#52697188
    DateTime=2017-01-20T14:16:20.7036270Z
System.Net.Sockets Verbose: 0 : [10808] DNS::GetHostAddresses()
    DateTime=2017-01-20T14:25:03.3938764Z
System.Net.Sockets Verbose: 0 : [10808] DNS::GetHostByName()
    DateTime=2017-01-20T14:25:03.3938764Z
System.Net.Sockets Verbose: 0 : [10808] Exiting DNS::GetHostByName()    -> IPHostEntry#39699746
    DateTime=2017-01-20T14:25:03.4094763Z
System.Net.Sockets Verbose: 0 : [10808] Exiting DNS::GetHostAddresses()     -> IPAddress[]#12400315
    DateTime=2017-01-20T14:25:03.4094763Z

跟踪配置:

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
            <source name="System.ServiceModel" 
                    switchValue="Critical, Error, Warning, Verbose , Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="sdt" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "c:\stacktrace_log.log" />
            </listeners>
         </source>
    </sources>
</system.diagnostics>

如果有人能帮忙解决这个问题,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

最后,我想出了这个问题。问题出在负载均衡器的连接超时,当请求超过负载均衡器中定义的限制时,该超时会断开连接。谢谢大家的帮助。