wpf 底层连接被关闭:连接被意外关闭 wcf
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15677294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The underlying connection was closed: The connection was closed unexpectedly wcf
提问by user746499
I am using WCF Services in WPF project. I have a large amount of data, about 847 000 records in table. this exception is throwed on client side
我在 WPF 项目中使用 WCF 服务。我有大量数据,表中大约有 847 000 条记录。这个异常是在客户端抛出的
In 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.')
In App.config
在 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>
In Web.Config
在 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>
Note: 1.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). 2.I debug it and all record retrieved from SQL server to my DAL; This Exception rises during 5-10 seconds, after I call from client this service function.
注意: 1.不适用于大量数据。在这种情况下,我在表中有大约 847 000 条记录。它可以完美地处理小数据(大约有 5000 - 6000 条记录)。 2.我调试它和从SQL服务器检索到我的DAL的所有记录;在我从客户端调用此服务功能后,此异常会在 5-10 秒内上升。
回答by Tassisto
I just added this line in my code
我刚刚在我的代码中添加了这一行
System.Net.ServicePointManager.Expect100Continue = false;
Hope this will help you.
希望这会帮助你。

