从wcf服务返回的json数据不完整

时间:2014-06-24 16:48:32

标签: c# json wcf

我正在从我的WCF服务中使用4个属性的.NET类返回JSON。问题是它被发送到浏览器(IE,Chrome,FF)。它只返回类

中的一个属性

.NET类:

[DataContract]
    public class MASInspections
    {
        [DataMember]
        public int MaintID { get; set; }
        public string MHID { get; set; }
        public DateTime MaintDate { get; set; }
        public string pdfReport { get; set; }

    }

.NET接口:

[OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Wrapped,
        UriTemplate = "GetInspectionByReach/{Reach}")]
    List<MASInspections> GetInspectionByReach(string Reach);

.NET方法:

 public List<MASInspections> GetInspectionByReach(string Reach)
    {
        List<MASInspections> InspInfos = new List<MASInspections>();
        DataSet ds = DBCalls.GetInspectionByReach(Reach);
        DataTable dt = ds.Tables[0];
        DataRowCollection drc = dt.Rows;
        for (int i = 0; i < drc.Count; i++)
        {
            object[] values = drc[i].ItemArray;
            MASInspections InspInfo = new MASInspections();
            InspInfo.MaintID = Convert.ToInt32(values[0]);
            InspInfo.MHID = Convert.ToString(values[1]);
            InspInfo.MaintDate = Convert.ToDateTime(values[5]);
            InspInfo.pdfReport = Convert.ToString(values[6]);
            InspInfos.Add(InspInfo);
        }

        return InspInfos;//this inlcudes all 4 properties
    }

当json被发送到浏览器时,只有MaintID存在:

    {"GetInspectionByReachResult":[{"MaintID":133},{"MaintID":178}]}

为什么会出现这种想法?

由于

1 个答案:

答案 0 :(得分:1)

这是你的问题:

[DataContract]
    public class MASInspections
    {
        [DataMember]
        public int MaintID { get; set; }
        public string MHID { get; set; }
        public DateTime MaintDate { get; set; }
        public string pdfReport { get; set; }

    }

你需要:

[DataContract]
    public class MASInspections
    {
        [DataMember]
        public int MaintID { get; set; }
        [DataMember]
        public string MHID { get; set; }
        [DataMember]
        public DateTime MaintDate { get; set; }
        [DataMember]
        public string pdfReport { get; set; }

    }