我有一个我用C#编写的WCF服务,它传递给调用者(C#WPF应用程序)一组实例化对象。工作得很好,但是如果我正在返回的集合有太多的对象,那么在大约10秒之后调用在客户端失败并带有一般异常(它本身包含一系列通用的内部异常)。这是例外和内部例外:
{“收到http://myserver/MyAppService/MyAppService.svc的HTTP响应时出错。这可能是由于 服务端点绑定不使用HTTP协议。这可以 也可能是由于服务器中止了HTTP请求上下文 (可能由于服务关闭)。请参阅服务器日志了解更多 详细信息。“}
{“底层连接已关闭:接收时发生意外错误。”} {“无法从传输连接读取数据:远程主机强行关闭现有连接。”} {“远程主机强行关闭现有连接”}
问题是100%可重现的,并且肯定与集合的大小有关,而不是内容。我知道这一点,因为如果我将单个集合拆分为多个较小的集合并一次将它们传回一个集合,它就可以正常工作。只有当它们在一起并且收集量很大时才会出现问题。
我尝试将客户端maxReceivedMessageSize
文件的app.config
属性增加到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>
我还可以更改或添加什么来使其工作?
谢谢!
答案 0 :(得分:2)
它可能是maxitemsinobjectgraph。启用wcf跟踪,您应该在那里看到堆栈跟踪。
答案 1 :(得分:2)
我记得在相似的声音情况之前我必须增加maxArrayLength。