Answered by:
Debugging a REST WCF Service

Question
-
I am new to the REST model with WCF. I downloaded the WCF Rest Service Template for .NET 4.0.
I have a project that is using the EF to retrieve a POCO entity from a database and then return that entity to the user.
The [WebGet] method executes properly and I can debug it to see the data being returned. However, it seems, when serializing the POCO object and trying to return it to the caller, the system is failing.
A few points here:
- I can create a manual POCO object and return it fine. However, when it is returning a POCO object sourced from the database (using EF), the call fails upon return (the EF query work properly--the WebGet method just doesnt return it back to the caller.
- The HTTP response code is 400 Bad Request. I don't get any other info (and no .NET exception).
- The same behavior occurs when running in IIS or the Visual Studio web server.
How should I go about debugging this issue?
Thanks!
Wednesday, December 22, 2010 11:25 PM
Answers
-
The IIS logs focus on the HTTP request / response codes. In the above case, the code was returning 400 without any further information. I was able to see the request and response details clearly. However, a problem was occuring before IIS was sending the response and .NET was not throwing an error.
After some further investigation, I found this to be a serialization issue.. The object that was trying to be serialized was not the POCO object, it was a System.Data.Entity.DynamicProxies class generated by EF.
- Proposed as answer by Steven Cheng - MSFT Tuesday, December 28, 2010 6:49 AM
- Marked as answer by Steven Cheng - MSFT Monday, January 3, 2011 3:42 AM
Thursday, December 23, 2010 4:24 PM
All replies
-
On 12/22/2010 6:25 PM, pmaroun wrote:> I am new to the REST model with WCF. I downloaded the WCF Rest Service> Template for .NET 4.0.>> I have a project that is using the EF to retrieve a POCO entity from a> database and then return that entity to the user.>> The [WebGet] method executes properly and I can debug it to see the data> being returned. However, it seems, when serializing the POCO object and> trying to return it to the caller, the system is failing.>> A few points here:>> 1. I can create a manual POCO object and return it fine. However,> when it is returning a POCO object sourced from the database> (using EF), the call fails upon return (the EF query work> properly--the WebGet method just doesnt return it back to the caller.> 2. The HTTP response code is 400 Bad Request. I don't get any other> info (and no .NET exception).> 3. The same behavior occurs when running in IIS or the Visual Studio> web server.>> How should I go about debugging this issue?Go look at the IIS error logs, use Google or Bing and look up how to do it..Thursday, December 23, 2010 5:12 AM
-
The IIS logs focus on the HTTP request / response codes. In the above case, the code was returning 400 without any further information. I was able to see the request and response details clearly. However, a problem was occuring before IIS was sending the response and .NET was not throwing an error.
After some further investigation, I found this to be a serialization issue.. The object that was trying to be serialized was not the POCO object, it was a System.Data.Entity.DynamicProxies class generated by EF.
- Proposed as answer by Steven Cheng - MSFT Tuesday, December 28, 2010 6:49 AM
- Marked as answer by Steven Cheng - MSFT Monday, January 3, 2011 3:42 AM
Thursday, December 23, 2010 4:24 PM