2013-03-26 225 views
0

我在我的WPF項目中使用WCF服務。 我有大量的數據,大約有847000條記錄在表中。此異常扔在客戶端底層連接已關閉:連接意外關閉 - wcf

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> 
     <client> 
      <endpoint address="http://localhost:5302/WpfStoreService.svc" 
       binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServices" 
       contract="proxy.IServices" name="BasicHttpBinding_IServices" /> 
     </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="52428899"> 
      <readerQuotas maxDepth="128" 
         maxStringContentLength="2147483647" 
         maxArrayLength="2147483647" 
         maxBytesPerRead="4096" 
         maxNameTableCharCount="2147483647" /> 
      <security mode="None"/> 
     </binding> 

     </basicHttpBinding> 
    </bindings> 

    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="True" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

你對WCF服務這個問題?

+0

有超時在你的配置:是不是那些10分鐘後存在的問題? – GameAlchemist 2013-03-26 09:36:27

+0

不,這個異常發生在30 - 40秒 – user746499 2013-03-26 09:44:21

回答

0

除非您已將其重寫到其他位置,否則默認的數據庫連接超時將成爲問題。

我認爲它可以被禁用,如果您將連接超時值設置爲0,但這取決於DbConnection實施;

嘗試將此添加到您的連接字符串。 Connect Timeout=0

"Data Source=.;Initial Catalog=AdventureWorksLT;Integrated Security=True;Connect Timeout=0"

+0

謝謝你的回覆,但不是工作:( 我注意到這個異常發生在大量的數據。如果我減少記錄的數量例如1000(現在我有847 000 )它可以工作 – user746499 2013-03-26 13:37:09

+0

任何想法?...... – user746499 2013-03-27 07:47:39

+0

只有一個其他的真的......不要在一個事務中選擇847000個記錄,而應該集中精力重新設計接口,以便使用更小的數據塊工作 – 2013-03-27 09:47:05

相關問題