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>

 

Wednesday, February 13, 2013

Parameter is not valid - System.Drawing.Image.FromStream

Two cases when you get this error:
1. When the stream is of 0 length or null
2. When the stream you are trying to save as image is not actually an image, like for eg: I have the stream of a pdf file received from a service and I am trying to convert this to an image.

 

Tuesday, February 5, 2013

System.Net.WebException: The request failed with HTTP status 403: Forbidden.

I found a web service failing with this error on the prod box.

I found following is the issue that caused this
Execute permission on the virtual directory of the service is set to none, where it should be set to 'ScriptsOnly'.
I set this back to 'ScriptsOnly' and the service started working
I do not need to do an iisreset