Wednesday, March 13, 2013

CommunicationException from wcf service

My wcf service takes xml as an input param. It fails when I try passing huge xmls to it but works for smaller ones. Following is the error I get when I try processing through the big xmls.
 

The adapter failed to transmit message going to send port "abcservice" with URL "abc.svc". It will be retransmitted after the retry interval specified for this Send Port. Details:"System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to abc.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.Socket.EndReceive(IAsyncResult asyncResult)

   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

   --- End of inner exception stack trace ---

   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

   at System.Net.PooledStream.EndRead(IAsyncResult asyncResult)

   at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)

   --- End of inner exception stack trace ---

   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)

   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)

   --- End of inner exception stack trace ---

I found the resolution to this is:
Adding maxRequestLength to System.web to change the default setting
 <httpRuntime maxRequestLength="16384" /> . Default value for this is 4MB  
If you do not already find the <htttpRuntime> in your config add one .
maxRequestLength="16384" (means 16MB since 1MB = 1024 kb)
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="16384" />
</system.web>