I am trying to return a POCO in WCF WebHttp Service. I am using EntityFramework 4.1 and generating the The entity is created entities using the DbContext Generator.
All works well with the EF. I can query the database and work with the entities. The problem comes from my WebHttp service. When I try to return a list of these entities, I get Error 324 (empty response) and when I try to return a single entity object, I get the WCF error - "Request Error". The service help page looks fine and sample responses are fine.
I tested the services by returning only the firstname of the entity changing the return type of the services to List and string. This works fine.
I assumed (having looked at a tutorial on WCF WebHttp Service) that there is no need to add [Serialize()] or other attributes to the entities.
I am lost as you why the service will not return an entity.
Thanks for any/all help. ROB
Here is the code for the service...
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class SearchService
{
[WebGet(UriTemplate = "Students")]
public List<coop_Students> GetStudents()
{
List<string> ret = new List<string>();
CottageDataEntities db = new CottageDataEntities();
var students = from s in db.coop_Students
where s.status == "enrolled"
orderby s.lastname, s.firstname
select s;
return students.ToList();
}
[WebGet(UriTemplate = "Echo/{text}")]
public string Echo(string text)
{
return "Hello " + text;
}
[WebGet(UriTemplate = "Students/{studentID}")]
public coop_Students GetStudent(string studentID)
{
using (CottageDataEntities db = new CottageDataEntities())
{
int id = int.Parse(studentID);
var student = db.coop_Students.FirstOrDefault(s => s.studentID == id);
return student;
}
}
}