简体   繁体   中英

WCF service gives no response while returning list of objects json

This is a weird one. so i have a WCF service returning JSON. It returns a list of objects. It works correctly if the list is empty, but the moment i add an object to the list i get "Could not get any response" error. I am using postman to test the service.

Here is my code.

public List<ProductDetails> GetProductsByCategory3(Stream s)
{    
    DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ProdPagenation));
    ProdPagenation result = (ProdPagenation)json.ReadObject(s);
    List<ProductDetails> pdl = new List<ProductDetails>();
    ProductDetails pd = new ProductDetails();//works well if this is not added to list.
    pdl.Add(pd);//As soon as a new object is added i get no response
    return pdl;
}

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    UriTemplate = "/GetProdByCat3")]
List<ProductDetails> GetProductsByCategory3(Stream s);



    [DataContract]
    public class ProductDetails
    {

    [DataMember]
       public int Id { get; set; }
    [DataMember]
       public string ITEM_ITEM_NAME { get; set; }
    [DataMember]
       public DateTime ITEM_ENTR_DATE { get; set; }
    [DataMember]
       public string ITEM_ITEM_STS { get; set; }
    [DataMember]
       public int ITEM_GRP_CODE { get; set; }
    [DataMember]
       public int ITEM_SBGRP_CODE { get; set; }
    [DataMember]
       public int ITEM_SBSBGRP_CODE { get; set; }
    [DataMember]
       public int Picid { get; set; }
    [DataMember]
       public string PicturePath { get; set; }
    }

I have no idea why its acting this way.

[DataContract]
 public class ProductDetails
        {
        // Apply the DataMemberAttribute to the property.
        [DataMember]
           public int Id { get; set; }
        [DataMember]
           public string ITEM_ITEM_NAME { get; set; }
        [DataMember]
           public DateTime ITEM_ENTR_DATE { get; set; }
        [DataMember]
           public string ITEM_ITEM_STS { get; set; }
        [DataMember]
           public int ITEM_GRP_CODE { get; set; }
        [DataMember]
           public int ITEM_SBGRP_CODE { get; set; }
        [DataMember]
           public int ITEM_SBSBGRP_CODE { get; set; }
        [DataMember]
           public int Picid { get; set; }
        [DataMember]
           public string PicturePath { get; set; }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM