【问题标题】:"The underlying connection was closed: The connection was closed unexpectedly." wcf service“底层连接已关闭:连接意外关闭。” wcf 服务
【发布时间】:2014-04-04 16:50:08
【问题描述】:

当我尝试从 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>

【问题讨论】:

  • 给定记录有多大?你可以发布你的配置文件吗?这可能是增加绑定限制但实际上并未使用绑定配置的情况。
  • 如果可能,或许您可以同时提供客户端和服务器配置 sn-ps 以供审核。

标签: .net performance web-services wcf visual-studio-2012


【解决方案1】:

此问题很可能与客户端或服务器配置有关。因此,您可能希望/需要尝试 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

【讨论】:

  • 上面的主程序(客户端)配置文件示例似乎没有使用最大值...
  • 我通过分页解决了这个问题。我设置的最大返回3000。有时间我想试试你的建议。
  • 好的。我很想知道设置客户端的 readerQuotas 值是否可以解决问题。问候。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
  • 1970-01-01
相关资源
最近更新 更多