locked
Issue in using the complex data json returned via service operation from WCF Data service RRS feed

  • Question

  • I am trying to return an IEnumerable via my service operation of WCF Data service. The operation runs fine in browser and returns json. However when I consume it in my client app via jQuery, firefox error console gives and error in json format. Below is my code to return complex data:

     

    [WebGet]
    public IEnumberable<ComplexType> GetNames()
    {
      return (this.CurrentdataSource.UserNames
          .Select(x => new {
            ID = x.ID,
            Name = x.Name
          }).ToList()
          .Select(x => new ComplexType {
            ID = x.ID,
            Name = x.Name
          }));
    }
    

     

    Here is the response:

     

    {
    "d" : [
    {
      "__metadata": { "type": "ComplexType" }, "ID": 1, "Name": "Name1"
    }, 
    {
      "__metadata": { "type": "ComplexType" }, "ID": 2, "Name": "Name2"
    }
    

     

    I even tried to return IQueryable, but the same result. My client is not able to parse the json data properly. The error logged in firefox error console is:

    Error: invalid label
    Source File: http://localhost/jQuerySample/MyDemo.aspx
    Line: 1
    Source Code:
    "d" : {
    Sunday, March 13, 2011 10:44 AM

All replies