2013-03-28 230 views
1

我在WPF项目中使用WCF服务。我有大量的数据,大约有847000条记录在表格中。此异常扔在客户端底层连接已关闭:连接意外关闭wcf

在VM

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中

<?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中

<?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> 

注: 它剂量不适用于大量的数据。在这种情况下,我在桌上有大约847000条记录。它可以完美地处理小数据(大约有5000 - 6000条记录)。 2.我调试它和从SQL服务器检索到我的DAL的所有记录;在我从客户端调用此服务功能后,此异常会在5-10秒内上升。

+4

你是否认真地通过电线发送了847000条记录?也许你应该考虑使用分页? – failedprogramming 2013-03-28 08:40:33

+0

我简单地测试过,它也没有工作7000记录 – user746499 2013-03-28 08:55:36

+0

为什么你不跟踪它。 http://stackoverflow.com/q/4271517/413032大多数类型的问题都可以通过跟踪来解决。看起来你的连接丢失了。 – 2013-03-28 09:42:11

回答

相关问题