Last post Jan 29, 2013 10:13 AM by CruzerB
Jan 24, 2013 01:10 PM|nirman.doshi|LINK
My database is having following table
Country >> CountryId, Country
Following is the exact architecture in my application.
Geography_EF >> Entity framework project (using EF 5) Geography_Model >> Model generated from EF (in short, entity classes). This contains Country class. Geography_WCF >> WCF application containing various service contracts.
The issue is that when I write an operation contract returning Country object (or collection) it gives me an error saying "The underlying connection is closed. "The underlying connection was closed: The connection was closed unexpectedly." Here, I can see
the call gets completed to this operation contract and immediately this exception occurs.
whereas if I write an operation to return a specific field only (i.e. CountryId or Country table) then it works fine.
I am using repository pattern and Unity container as well.
What do you think, I am missing?
Jan 29, 2013 04:57 AM|Haixia Xie - MSFT|LINK
The issue may caused by WCF was unable to serialize the circular reference that Entity Framework created when loading the referenced entities, try put DataContract(IsReference = true)] above your model class. For details refer:
If the issue still exists, suggest you enable tracing for your service to help to dignose the actual issue.
Jan 29, 2013 10:13 AM|CruzerB|LINK
You have to detach the returning entity object from context before sending via WCF.