I'm returning JSON from a NET class with 4 properties from my WCF service. The problem is when it gets sent to the browser (IE, Chrome, FF). it only returns one of the properties from the class
.NET class:
[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 Interface:
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "GetInspectionByReach/{Reach}")]
List<MASInspections> GetInspectionByReach(string Reach);
.NET Method:
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
}
when the json gets sent to the browser, only the MaintID is there:
{"GetInspectionByReachResult":[{"MaintID":133},{"MaintID":178}]}
Any ideas why this would be?
Thanks
this is your problem:
[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; }
}
you need:
[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; }
}
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.