"The underlying connection was closed: The connection was closed unexpectedly." WCF 服务



当我尝试从 wcf 服务返回大量数据时。我回来时崩溃了。消息为"基础连接已关闭:连接意外关闭。

我已经阅读了有关此问题的提示;它们对我没有帮助。我尝试增加绑定参数无济于事。我添加了一个跟踪,它没有给我任何有用的信息。

我发现我可以毫无问题地返回 3274 条记录,但 3275 是一个问题。

我可以尝试分页,但这是最后的手段。

这是主程序中配置文件的关键部分

 <bindings>
            <basicHttpBinding>                 
              <binding name="BasicHttpBinding" closeTimeout="00:01:00"
                  openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                  allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                  maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"
                  messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                  useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                  <transport clientCredentialType="None" proxyCredentialType="None"
                    realm="" />
                  <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
              </binding>  
            </basicHttpBinding>
        </bindings>

和来自WCF

<binding closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00"
      sendTimeout="00:10:00" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None" />
    </binding>

此问题很可能与客户端或服务器配置有关。 因此,您可能希望/需要试验 readerQuota 值。 (作为参考,以下内容表示最大值)。

<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
              maxArrayLength="2147483647" maxBytesPerRead="2147483647"
              maxNameTableCharCount="2147483647" />

您可能希望在客户端和服务器上启用 WCF 跟踪,并查看日志以帮助确定基础错误/原因。

参考: http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx

相关内容

最新更新