【问题标题】:System.Net.Web Exception in WCF serverWCF 服务器中的 System.Net.Web 异常
【发布时间】:2014-12-10 04:13:43
【问题描述】:

我在尝试将文件夹的所有文件发送到服务器然后将处理后的输出发送到 C# 控制台客户端时抛出以下异常..

以下是例外,

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a
receive. ---> System.IO.IOException: Unable to read data from the transport 
connection: An existing connection was forcibly closed by the remote host. ---> 
System.Net.Sockets.SоcketException: An existing connection was forcibly closed by the remote host
аt System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

如果我处理与单个文件相同的文件,它可以正常工作。

以下是使用的绑定参数,

在服务器的 web.config 中:

<binding name="ExtendedMaxSize" 
               openTimeout="10:01:00" 
               receiveTimeout="10:10:00" 
               sendTimeout="10:01:00"
               maxBufferPoolSize="2147483647" 
               maxReceivedMessageSize="2147483647"
               messageEncoding="Text" 
               textEncoding="utf-8">
   <readerQuotas maxDepth="64"
                 maxStringContentLength="2147483647"
                 maxArrayLength="2147483647"
                 maxBytesPerRead="8192"
                 maxNameTableCharCount="16384"/>
   <security mode="None">
     <transport clientCredentialType="None"/>
   </security>

在客户端的 app.config 中:

<binding name="WSHttpBinding_InterfaceWCFServer1"
         openTimeout="10:01:00" 
         receiveTimeout="10:10:00" 
         sendTimeout="10:01:00"
         bypassProxyOnLocal="false" 
         transactionFlow="false"
         hostNameComparisonMode="StrongWildcard" 
         maxBufferPoolSize="2147483647"
         maxReceivedMessageSize="2147483647" 
         messageEncoding="Text"
         textEncoding="utf-8" 
         useDefaultWebProxy="true" 
         allowCookies="false">
 <readerQuotas maxDepth="64" 
               maxStringContentLength="2147483647"
               maxArrayLength="2147483647" 
               maxBytesPerRead="8192" 
               maxNameTableCharCount="16384" />
 <security mode="None">
   <transport clientCredentialType="None" 
              proxyCredentialType="None"
              realm="">
     <extendedProtectionPolicy policyEnforcement="Never" />
   </transport>
   <message clientCredentialType="Windows" 
            negotiateServiceCredential="true"
            algorithmSuite="Default" 
            establishSecurityContext="true" />
  </security>
</binding>

我在笔记本电脑中使用 8 GB RAM,服务器和客户端都在同一台机器上。

在任务管理器中看到Processes 时,我发现 w3wp.exe 的使用量从 700 MB 到 6 GB,当使用量达到 95% 的限制时,我会抛出此异常,并且 @ 使用的内存987654325@ 减少到 700 mb 左右,然后再次为每个请求增加,直到达到大约 95% 的内存。所以此时我抛出了这个异常。

【问题讨论】:

  • 下次正确格式化您的问题!

标签: c# wcf exception iis w3wp


【解决方案1】:

显然,您的 WCF 服务器将所有数据存储在内存中,因此您最终会耗尽可用内存。这会导致在服务器中引发 OOM 异常,从而可能会终止进程。这会终止 TCP 连接。

重做您的服务器设计,使其不需要无限量的内存。

【讨论】:

  • 在哪里更改最大限制?
  • 在您当地的五金店。购买更多内存。或者,阅读我的回答。
猜你喜欢
  • 2017-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多