I am new to WCF. I am trying to create List with LINQ result by using Entity Framework. I want to return JSON data. But i am not able to get it. I am getting error like Notsupportedexception was unhandled by user code. Please help me to solve this problem. Thanks in advance.
This is my Service Constructor:
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "getcontact")]
List<string> JSONDataAll();
If i return like this its working fine:
public List<String> JSONDataAll()
{
var users = (from u in db.Tbl_Users select u).ToList();
var finalList= users.Select(u => u.UserName).ToList();
return st;
}
In this case its showing error:
public List<String> JSONDataAll()
{
var users = (from u in db.Tbl_Users
select new
{ u.UserName,
u.UserAddress
}).ToList();
return users;
}