当我从Postman调用REST方法时,将按以下顺序返回数据:
IOW:
VendorId
VendorItemID
Id
PackSize
当我从客户端应用程序调用REST方法时:
private IEnumerable<VendorItem> GetCollectionOfVendorItems()
{
ArrayList arrList =
FetchDataFromServer("http://localhost:21608/api/vendoritem/getall");
String contents = "<VendorItems>";
foreach (String s in arrList)
{
contents += s;
}
contents += "</VendorItems>";
String unwantedPreamble = "<ArrayOfVendorItem xmlns:i=\"http://www.w3.org/2001/XMLSchema-
instance\" xmlns=\"http://schemas.datacontract.org/2004/07/CStore.DomainModels.HHS\">";
contents = contents.Replace(unwantedPreamble, String.Empty);
contents = contents.Replace("</ArrayOfVendorItem>", String.Empty);
XDocument xmlDoc = XDocument.Parse(contents);
IEnumerable<VendorItem> vendorItems = xmlDoc.Descendants("VendorItem").Select(x =>
GetVendorItemForXMLElement(x));
return vendorItems;
}
private static VendorItem GetVendorItemForXMLElement(XElement vendor)
{
return new VendorItem
{
Id = vendor.Element("Id").Value,
PackSize = Convert.ToInt32(vendor.Element("PackSize").Value),
VendorId = vendor.Element("VendorId").Value,
VendorItemID = vendor.Element("VendorItemID").Value
//VendorId = vendor.Element("VendorId").Value,
//VendorItemID = vendor.Element("VendorItemID").Value,
//Id = vendor.Element("Id").Value,
//PackSize = Convert.ToInt32(vendor.Element("PackSize").Value)
};
}
public class VendorItem
{
public string Id { get; set; }
public int PackSize { get; set; }
public string VendorId { get; set; }
public string VendorItemID { get; set; }
public String siteNum { get; set; }
//public string VendorId { get; set; }
//public string VendorItemID { get; set; }
//public string Id { get; set; }
//public int PackSize { get; set; }
//public String siteNum { get; set; }
}
...它按此顺序返回元素:
(你听说过Big Data,那是Wavy Gravy的数据)
IOW:
Id
PackSize
VendorId
VendorItemID
即使班级中的成员顺序与邮递员的回报相符,也没有区别;无论哪种方式,我先得到Id等等。
为什么会这样?这似乎并不重要,但我错了吗?
c#REST postman xml json