Posts Tagged ‘Json’

CommunicationException get thrown when returning collection from entity framework with WCF service

September 22, 2013 Leave a comment

Hello All, Again some issue with Two technologies (WCF and Entity framework).

I have a service method which return entity object with child entity as a collection. But when it returning response to end client it is throwing something out of mind exception. it says

“CommunicationException get thrown: An error occurred while receiving the HTTP response to http://localhost:8080/. 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.”

Firstly, I didn’t understood the exception that what is happening. I researched through fiddler and other tools but i did not got any proper error details. nothing was going on way.

So I used a trick to serialize the returning collection prior to sending to client. And my trick got worked, When serializing the object I received “A circular reference was detected while serializing an object “.

So after searching on net i found that navigation property inside child element for parent entity was creating the issue. It was serializing child and parent entities again and again.


So after removing parent navigation property from child entity I was able to return parent and child records without any error.

Please note that this problem will only occur when you are serializing the entity object.

Please post me with such issues which you have faced with WCF and Entity framework so it will help other who are facing the issue & wasting their time researching the error.

Thank you,