Home > Uncategorized > Entity framework and WCF service nightmare : “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”

Entity framework and WCF service nightmare : “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”

Hi Guys,

I started playing on WCF with Entity fx 5 recently. I got a requirement where I had to fetch parent and child record based on provided id.

I started to write a simple linq query which will return me a row with parent and child record. everything was on way to build and test service. The nightmare just started when i faced “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.”

 

I started searching on net but could not got the correct resolution. After 3 hours continuous research given me an answer by deeply studying datacontext object.

There is a property named “ProxyCreationEnabled” which creates the proxy for an object which will help in tracking and lazy loading operations. When it is set to “true” it will prevent object from serializing and that’s why I was facing the above error.

 

So by setting it to “false” made my query started working. Also to boost the performance of queries you should set it “false”.

You can find it in context as

contextObj.Configuration.ProxyCreationEnabled = false;

Thank you,

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: