简体   繁体   中英

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. 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). 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."}
{"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. 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. Also tried increasing the timeout period, but no affect. Here are the properties in the app.config file. I've tried increasing pretty much every number below to 2147483647 and tried changing maxBufferPoolSize to 0, but no luck:

<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. Enable the wcf trace, you should see a stack trace in there.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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