【问题标题】:WCF Socket Timeout Exception while carrying large data携带大数据时出现 WCF 套接字超时异常
【发布时间】:2014-01-29 13:42:12
【问题描述】:

我正在新研究 Web 服务 WCF,并且我被分配了在大数据情况下测试 Web 服务的责任。所以,通过Entity Object,我携带了大约。 16000+ 条记录,但我的代码抛出异常,如:

套接字连接被中止。这可能是由于处理您的消息时出错或远程主机超出接收超时,或者是潜在的网络资源问题引起的。本地套接字超时为 '00:24:59.9989991'。

虽然我在 App.Config and Web.Config 文件中将 Socket Timeout5 增加到 25,但仍然存在相同的错误。这让我相信一定有大数据问题。

App.Config

<bindings>  
  <netTcpBinding>  
    <binding name="tcpBinding"  
              maxBufferSize="2147483647"  
              maxReceivedMessageSize="2147483647"  
              maxBufferPoolSize="2147483647"  
             receiveTimeout="00:06:00" sendTimeout="00:06:00" >  
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />  
      <security mode="None" />  
    </binding>  
  </netTcpBinding>  
  <webHttpBinding>  
    <binding name="RESTBinding"  
              maxBufferSize="2147483647"  
              maxReceivedMessageSize="2147483647"  
              maxBufferPoolSize="2147483647"  
             receiveTimeout="00:06:00" sendTimeout="00:06:00" >  
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />  
      <security mode="None" />  
    </binding>  
  </webHttpBinding>  
</bindings>  

cs 文件

userObject = client.GetAll().ToList();

而且,GetALL() 有这样的定义:

var result = (from user in entity.User select user).ToList();
    return result;

而且,上面的代码返回了 16000+ 条记录,但是由于哪个 webservice 给出了异常。 我从网上对该主题进行了研发,但没有找到任何有用的答案,谁能建议我该怎么做。

【问题讨论】:

  • Local socket timeout was '00:24:59.9989991'. 25 好像不够长。
  • 那么双重ToList() 可能也无济于事......

标签: c# wcf web-services sockets


【解决方案1】:

一个好的决定是将您的大数据分成更小的数据包。

【讨论】:

  • 你能解释一下我如何实现它
【解决方案2】:

修改 API 以“分页”结果。换句话说,而不是GetALL() 公开Get(int start, int end) 并让用户一次通过它们。 GetALL 中的代码将更改为:

var result = (from user in entity.User select user).Skip(start).Take(end-start).ToList();
    return result;

这对您的用户来说也是一件更好的事情,这样您就不会用太多的数据压倒他们。

【讨论】:

  • 感谢您的及时回复,很抱歉这么晚才回复您,我这样做是为了进行压力测试,以供将来我的实体必须通过大量数据时参考,所以,这就是我选择所有记录的原因,你能解释一下.skip().Take() 会做什么,因为我是新手
  • 你的代码抛出错误:The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'
  • @HarshSharma 这是SkipTake 的文档。以这种方式使用它们只会将集合分成块。为避免该错误,请添加OrderBy 方法并对user 的某些属性进行排序:(from user in entity.User select user).OrderBy(u =&gt; u.Name).Skip(start).Take(end-start)
猜你喜欢
  • 2017-11-16
  • 2011-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
  • 2012-09-06
相关资源
最近更新 更多