这很奇怪。所以我有一个返回JSON的WCF服务。它返回一个对象列表。如果列表为空,它可以正常工作,但是当我将一个对象添加到列表时,我得到“无法获得任何响应”错误。我正在使用邮递员来测试服务。
这是我的代码。
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; }
}
我不知道为什么这样做。
答案 0 :(得分:0)
[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; }
}