简体   繁体   English

WCF服务调用因传递太多数据而失败?

[英]WCF Service Call Failing Due To Too Much Data Being Passed?

I've got a WCF service that I've written in C# which passes to the caller (a C# WPF application) a collection of instantiated objects. 我有一个用C#编写的WCF服务,该服务将实例化对象的集合传递给调用方(一个C#WPF应用程序)。 Works great, however if the collection I'm returning has too many objects, the call fails on the client side after about 10 seconds with a generic exception (which itself contains a series of generic inner exceptions). 效果很好,但是如果我要返回的集合有太多对象,则调用将在大约10秒钟后在客户端失败,并带有一个通用异常(该异常本身包含一系列通用内部异常)。 Here is the exception and inner exceptions: 这是异常和内部异常:

{"An error occurred while receiving the HTTP response to http://myserver/MyAppService/MyAppService.svc . This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."} {“收到对http://myserver/MyAppService/MyAppService.svc的HTTP响应时发生错误。这可能是由于服务端点绑定未使用HTTP协议。这也可能是由于HTTP请求上下文被中止了由服务器(可能是由于服务关闭)引起的。有关更多详细信息,请参阅服务器日志。“}
{"The underlying connection was closed: An unexpected error occurred on a receive."} {“底层连接已关闭:接收时发生意外错误。”}
{"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."} {“无法从传输连接读取数据:现有连接被远程主机强行关闭。”}
{"An existing connection was forcibly closed by the remote host"} {“现有连接被远程主机强行关闭”}

The issue is 100% reproduceable and is definitely related to the size of the collection, and not the content. 问题是100%可复制的,并且绝对与收藏的大小有关,而不与内容有关。 I know this because if I break up the single collection in to multiple smaller collections and pass those back one at a time, it works fine. 我知道这是因为,如果我将单个集合分解为多个较小的集合,然后一次将它们传递回一个,则效果很好。 Only when they're all together and the collection is to large is it a problem. 只有当他们在一起并且收藏很大时,这才是问题。

I tried increasing the maxReceivedMessageSize property on the client side's app.config file to 2147483647 but the error still persists. 我尝试将客户端的app.config文件中的maxReceivedMessageSize属性增加到2147483647,但错误仍然存​​在。 Also tried increasing the timeout period, but no affect. 还尝试增加超时时间,但没有影响。 Here are the properties in the app.config file. 这是app.config文件中的属性。 I've tried increasing pretty much every number below to 2147483647 and tried changing maxBufferPoolSize to 0, but no luck: 我尝试将下面的几乎每个数字都增加到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>

What else could I change or add to make this work? 我还可以更改或添加哪些功能以使其正常工作?

Thanks! 谢谢!

It could be maxitemsinobjectgraph. 可能是对象图中的maxitems。 Enable the wcf trace, you should see a stack trace in there. 启用wcf跟踪,您应该在其中看到堆栈跟踪。

我记得在类似的发声情况下,我不得不增加maxArrayLength。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM