I'm developing a WCF web service using visual studio, and I'm using LINQ to query from the database. The problem is, when the function return a List of Ilist, the browser show me an error
The web page is not available
. This is my code in the interface:
[OperationContract, WebGet(ResponseFormat=WebMessageFormat.Json)]
IList<Person_type> GetPeopleTypes();
And this is the implementation code of the function:
public IList<Person_type> GetPeopleTypes()
{
IList<Person_type> result=new List<Person_type> ();
IList<Person_type> pts = db.Person_type.ToList();
foreach (Person_type pt in pts)
result.Add(pt) ;
return result;
}
What is the problem?
It is not good idea to return interface types from WCF-services (beacause of serialization problems https://stackoverflow.com/a/6732883/4585429).
Try to rewrite your method like this:
or like this: