【发布时间】:2012-02-17 19:48:48
【问题描述】:
我有一个用 C# 编写的 WCF 服务,该服务将实例化对象的集合传递给调用者(C# WPF 应用程序)。效果很好,但是如果我返回的集合有太多对象,则在大约 10 秒后调用在客户端失败并出现通用异常(其本身包含一系列通用内部异常)。下面是异常和内部异常:
{"接收到http://myserver/MyAppService/MyAppService.svc 的 HTTP 响应时发生错误。这可能是由于 服务端点绑定不使用 HTTP 协议。这可以 也可能是由于服务器中止了 HTTP 请求上下文 (可能是由于服务关闭)。查看服务器日志了解更多信息 详细信息。”}
{“底层连接已关闭:接收时发生意外错误。”}
{“无法从传输连接读取数据:现有连接被远程主机强行关闭。”}
{"一个现有的连接被远程主机强行关闭"}
这个问题是 100% 可复制的,并且肯定与集合的大小有关,而不是与内容有关。我知道这一点,因为如果我将单个集合分解为多个较小的集合并一次将它们传回一个,它就可以正常工作。只有当它们都在一起并且集合很大时才会有问题。
我尝试将客户端app.config 文件上的maxReceivedMessageSize 属性增加到2147483647,但错误仍然存在。还尝试增加超时时间,但没有影响。以下是app.config 文件中的属性。我尝试将以下几乎所有数字都增加到 2147483647,并尝试将 maxBufferPoolSize 更改为 0,但没有运气:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_iMyAppService"
closeTimeout="01:00:00" openTimeout="01:00:00"
receiveTimeout="01:00:00" sendTimeout="01:00:00"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="524288"
maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas
maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_iMyAppService"
closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas
maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint name="CurrencyConvertorSoap"
address="http://www.webservicex.net/CurrencyConvertor.asmx"
binding="basicHttpBinding"
bindingConfiguration="CurrencyConvertorSoap"
contract="CurrencyConverterService.CurrencyConvertorSoap" />
<endpoint name="CurrencyConvertorSoap12"
address="http://www.webservicex.net/CurrencyConvertor.asmx"
binding="customBinding"
bindingConfiguration="CurrencyConvertorSoap12"
contract="CurrencyConverterService.CurrencyConvertorSoap" />
<endpoint name="WSHttpBinding_iMyAppService"
address="http://myserver/MyAppService/MyAppService.svc"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_iMyAppService"
contract="MyAppService.iMyAppService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint name="BasicHttpBinding_iMyAppService"
address="http://myserver/MyAppService/MyAppService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_iMyAppService"
contract="MyAppService.iMyAppService" />
</client>
我还可以更改或添加什么来完成这项工作?
谢谢!
【问题讨论】:
标签: c# wpf wcf web-services endpoint