Question

I'm using wcf service in my c# mvc application. I need to get through wcf to the client side (to the controller) a large amount of data (approximately 20000 records).

In the local version - I get all the records very well, but in the server version I don't get anything if I don't limit the query to 1000 records.

When it's not limited and trying to bring all the records, this is what I get in client log:

System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to xxx/WCF.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. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace ---

I've added this to web.config in client but it didn't help:

<behaviors>
      <endpointBehaviors>
        <behavior >
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

Any ideas?

Was it helpful?

Solution

Is your binding configuration set to allow large data? If you are using an httpbinding you should configure your endpoint and your service in this way

<basicHttpBinding>
<binding name="LargeDataBindingConfiguration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false">
<readerQuotas maxDepth="32" maxStringContentLength="998192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>

Other then that try to increase on your server the maximum length of content in a request supported by the IIS

<security>
    <requestFiltering>
        <requestLimits maxAllowedContentLength="4294967295" />
    </requestFiltering>
</security>

OTHER TIPS

As Mackho said, this you should increase the timeouts in the first configuration settings. Also, the clients must increase their timeout values and the maximum content that they can get from the server.

Additional, you can use streaming for your service if you really need to pass all the data and don't want to use paging. To configure your service to run in stream mode, add:

<bindings>
     <basicHttpBinding>
        <binding transferMode="Streamed" name="LargeDataBindingConfiguration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="false">
        <readerQuotas maxDepth="32" maxStringContentLength="998192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
        </binding>
    </basicHttpBinding>
</bindings>

Note that your client settings are also important:

  • The lowest timeouts will prevail (from the client or the server)
  • The lowest between maxStringContentLength and the settings from the client about how much they can receive will prevail
  • To use streaming, the client must support it and have the same setting too (otherwise, on the client the data will be buffered)

It really depends if the exception is thrown by the server or by the client. Enable WCF tracing in both of them and see where the exception is thrown, then do the necessary configurations on that side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top