Archive

Posts Tagged ‘lazy loading’

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”

September 16, 2013 Leave a comment

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