West Sider

West Sider

  • NA
  • 40
  • 23.3k

WCF problem in WPF: The underlying connection was closed

Mar 27 2013 6:42 AM
I am using WCF Services in my WPF project. I have a large amount of data, about 847000 records in table. this exception is throwed on client side The underlying connection was closed: The connection was closed unexpectedly

Here is fragment of my code and config files:
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.')

In my 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:7902/WpfStoreService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServices"
                contract="proxy.IServices" name="BasicHttpBinding_IServices" />
        </client>
    </system.serviceModel>
</configuration>




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


    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>  
  </system.webServer>
Did you have this problem on WCF Services?


Note: It dose not work with large amount of data. In this case I have about 847 000 records in table. It works with small data perfectly(with about 5000 - 6000 records)

Answers (7)