1

我在 WPF 项目中使用 WCF 服务。我有大量数据,表中有大约 847 000 条记录。此异常在客户端引发

在虚拟机中

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>

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

4

1 回答 1

1

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

System.Net.ServicePointManager.Expect100Continue = false;

在 MSDN 上找到解释

希望这会帮助你。

于 2013-12-26T11:59:54.183 回答