首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基础连接被关闭:连接意外地关闭

基础连接被关闭:连接意外地关闭
EN

Stack Overflow用户
提问于 2013-03-28 08:37:32
回答 1查看 9.5K关注 0票数 1

我在WPF项目中使用WCF服务。我有大量的数据,大约有847000份记录在表中。此异常将在客户端抛出。

在VM中

代码语言:javascript
复制
proxy.ServicesClient client = new proxy.ServicesClient();
var result = client.GetCustomers(); // here throws ('ComunicationException was unhandled by user code: The underlying connection was closed: The connection was closed unexpectedly.')

在App.config中

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
      <bindings>
        <basicHttpBinding>
          <binding name="BasicHttpBinding_IServices" closeTimeout="00:10:00"
              openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
              maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
            <security mode="None" />
          </binding>
        </basicHttpBinding>
      </bindings>
      <behaviors>
        <endpointBehaviors>
          <behavior name="clientBehavior">
            <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          </behavior>
        </endpointBehaviors>
      </behaviors>
        <client>
            <endpoint address="http://localhost:7902/WpfStoreService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServices"
                contract="proxy.IServices" name="BasicHttpBinding_IServices" behaviorConfiguration="clientBehavior" />
        </client>
    </system.serviceModel>
</configuration>

在Web.Config中

代码语言:javascript
复制
<?xml version="1.0"?>
<configuration>

  <connectionStrings>
    <add name="AdventureWorksLTConnectionString" connectionString="Data Source=.;Initial Catalog=AdventureWorksLT;Integrated Security=True;" />
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>

  <system.serviceModel>    

    <bindings>
      <basicHttpBinding>    
        <binding name="BasicHttpBinding_IServices" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"
                 maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647"
                        maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="214748364"
                        maxNameTableCharCount="2147483647"/>

          <security mode="None"/>
        </binding>

      </basicHttpBinding>
    </bindings>

    <services>
      <service name="WpfStore.Services.Services" behaviorConfiguration="debugbehavior">
        <endpoint address="" binding="basicHttpBinding" contract="WpfStore.Services.Contracts.IServices" bindingConfiguration="BasicHttpBinding_IServices"/>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="debugbehavior">
          <serviceMetadata httpGetEnabled="true"/> 
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>   
  </system.webServer>  
</configuration>

注:1.不适用于大量数据。在这个例子中,我在表中有大约847000份记录。它能很好地处理小数据(大约有5000到6000条记录)。2.调试它和从server检索到我的DAL的所有记录;在我从客户端调用这个服务函数之后,这个异常在5-10秒内上升。

EN

回答 1

Stack Overflow用户

发布于 2013-12-26 11:59:54

我刚在代码中添加了这一行

代码语言:javascript
复制
System.Net.ServicePointManager.Expect100Continue = false;

寻找对MSDN的解释

希望这能帮到你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15677294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档