5

I am creating a WCF web api service. My problem is that some methods return a 200/OK response, but the headers and the body are empty.

In setting up my web service, I created an ADO.NET Entity Data Model. I chose ADO.NET DbContext Generator when I added a code generation item. In the Model.tt document, I changed HashSet and ICollection to List. I built my website.

It used to be that when I coded a method to return a List of an entity (like List<Customer> or List<Employee> in the Northwind database), it worked fine. Over time, I could not return a List of any of those, and could only grab one entity. Now, it's gotten to a point where I can return a List<string> or List<int>, but not a List or an instance of any entity. When I try to get a List<AnyEntity>, the response is 200/OK, but the response headers and body are empty.

I have tried using the debugger and Firefox's Web Console. Using FF's WC, I could only get an "undefined" status code. I am not sure where to go from here.

EDIT: In trying to grab all Areas from the database, I do this:

[WebGet(UriTemplate = "areas")]
public List<a1Areas> AllAreas()
{
    return context.a1Areas.ToList();
}

I would appreciate any more methods for debugging this. Thanks in advance.

Found the answer, thanks to Merlyn!

In my Global.asax file, I forgot to comment out two lines that took care of proxies and disposing of my context object. The code is below:

void Application_BeginRequest(object sender, EventArgs e)
{
  var context = new AssignmentEntities();
  context.Configuration.ProxyCreationEnabled = false;
  HttpContext.Current.Items["_context"] = context;
}

void Application_EndRequest(object sender, EventArgs e)
{
  var context = HttpContext.Current.Items["_context"] as AssignmentEntities;
  if (context != null)
  {
    context.Dispose();
  }
}
7
  • 1
    Are you returning entities directly to the client? This might not work the way that you'd hope, due to entity proxies/lazy loading. Can you supply some code for your service methods? Also, Fiddler is a good tool for debugging requests. Grabbing request and response data out of there and pasting it in the question might also be helpful. Oct 31, 2011 at 2:05
  • Thanks for the info! :) How does your context get created/disposed? Oct 31, 2011 at 2:54
  • Hello! Yes, I am returning the entities directly to the client. As for using Fiddler, the response was: HTTP/1.1 504 Fiddler - Receive Failure Content-Type: text/html; charset=UTF-8 Connection: close Timestamp: 22:49:24.129 ReadResponse() failed: The server did not return a response for this request.
    – daoberes
    Oct 31, 2011 at 2:56
  • Thanks for the tip about proxies! I took a look at my Global.asax file, where I created my context. I forgot to comment out a couple of lines: context.Configuration.ProxyCreationEnabled = false; and context.Dispose(). I will put the code to answer my own question, in case anyone has issues with this later. Thank you so much again!
    – daoberes
    Oct 31, 2011 at 3:05
  • 1
    No problem! Feel free to post an actual answer to your own question and accept it. That is accepted and encouraged here. Oct 31, 2011 at 3:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.