none
unable to return nested type to client from wcf json enabled service RRS feed

  • Question

  • I am unable to return nested type from wcf json service. When I do http get from RestClient (firefox) the service operation is executed twice and the response body is empty.
    calling the same service from url in chrome returns 
    No data received. Error 324 ERR_EMPTY_RESPONSE

    here's the code

    [WebInvoke(Method=”GET”, ResponseFormat=WebMessageFormat.Json, RequestFormat= WebMessageFormat.Json, UriTemplate=”GetProducts/storedId”]
    public ServiceResponse<List<Product>>> GetAllProducts(string storeId)
    {
       // code to get list of products from the db.
    }
    [DataContract]
    public class Product
    {
       [DataMember]
       public string Name {get; set;}
    
       [DataMember]
       public IList<ProductDetails> ProductDetails {get; set;}
    }
    Could someone please suggest what's going wrong. Thanks


    -= JL =-


    • Edited by Job Lot Thursday, January 24, 2013 1:29 AM
    Thursday, January 24, 2013 1:26 AM

Answers

All replies

  • Hi,There is no problem when I try to return a IList<object> type. I do not get what nested type you want to return. Here is my test

    //IService
    [WebInvoke(UriTemplate = "all", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
            IList<Employee> GetAll();
    
    //Service
      public IList<Employee> GetAll()
            {
                return employees;
            }

    Friday, January 25, 2013 8:10 AM
  • Hi MiniPeter

    Does your employee class has a reference to another custom type? for instance

    public class Employee{

    public string Name {get;set;}

    public IList<Project> Projects {get;set;}

    }

    public class Project{

    public string Name {get;set;}

    public Employee Employee {get;set;}

    }


    -= JL =-


    • Edited by Job Lot Tuesday, January 29, 2013 2:57 AM
    Tuesday, January 29, 2013 2:55 AM
  • I got WCF to use Json.NET (http://json.codeplex.com/) to convert between .NET objects and JSON

    -= JL =-

    • Marked as answer by Job Lot Wednesday, February 6, 2013 2:25 AM
    Wednesday, February 6, 2013 2:25 AM