Предоставляет xml в строке из запроса. После десериализации я не могу получить какое-либо значение из xml с помощью метода get
. Также в Vehicle.cshtml
я пытался получить значение DeviceId
. На метку html он получает только строковое имя DeviceId
. Не получая ценности. Что не так с моим путем? Как я могу получить эти значения xml из представления?
DataSet.cs
using System;
using System.Xml.Serialization;
namespace ShippingProject.Models
{
// [System.Xml.Serialization.XmlRootAttribute("DataSet", Namespace = "http://www.arvento.com/", IsNullable = false)]
[XmlRoot("DataSet")]
public class DataSet
{
[XmlElement("Device_x0020_No")]
public string DeviceId { get; set; }
[XmlElement("Latitude")]
public double Latitude { get; set; }
[XmlElement("Longitude")]
public double Longitude { get; set; }
[XmlElement("Address")]
public string Address { get; set; }
}
}
HomeController.cs
public IActionResult Vehicle()
{
// Create web client.
WebClient client = new WebClient();
// Download string.
string value = client.DownloadString("http://ws.arvento.com//v1/report.asmx/GetVehicleStatus?Username=username&PIN1=password&PIN2=password&Language=string");
// Write values.
Console.WriteLine("--- WebClient result ---");
Console.WriteLine(value.Length);
Console.WriteLine(value);
XmlSerializer serializer = new XmlSerializer(typeof(List<DataSet>), new XmlRootAttribute("DataSet"));
// DataSet result;
var ms = new MemoryStream(Encoding.UTF8.GetBytes(value));
var rdr = new XmlTextReader(ms) { Namespaces = false };
// StringReader rdr = new StringReader(value);
/* using (TextReader rdr = new StringReader(value))
{
result = (DataSet)serializer.Deserialize(reader);
}
StreamReader rdr = new StreamReader(value);*/
List<DataSet> datasetList = (List<DataSet>)serializer.Deserialize(rdr);
Console.WriteLine("--- Deserialize result ---");
Console.WriteLine(datasetList);
datasetList.ForEach(dl => {
Console.WriteLine(dl.DeviceId);
Console.WriteLine(dl.Latitude);
Console.WriteLine(dl.Longitude);
Console.WriteLine(dl.Address);
Console.WriteLine();
});
return View();
}
Vehicle.cshtml
@model DataSet
@Html.LabelFor(model => model.DeviceId)
это мой xml файл:
<DataSet xmlns="http://www.arvento.com/">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="tblVehicleStatus">
<xs:element name="tblVehicleStatus" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="dtVehicleStatus">
<xs:complexType>
<xs:sequence>
<xs:element name="Device_x0020_No" type="xs:string" minOccurs="0"/>
<xs:element name="GMT_x0020_Date_x002F_Time" type="xs:dateTime" minOccurs="0"/>
<xs:element name="Latitude" type="xs:double" minOccurs="0"/>
<xs:element name="Longitude" type="xs:double" minOccurs="0"/>
<xs:element name="Speed" type="xs:double" minOccurs="0"/>
<xs:element name="Address" type="xs:string" minOccurs="0"/>
<xs:element name="Building_x0020__x002F__x0020_Region" type="xs:string" minOccurs="0"/>
<xs:element name="Height" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<tblVehicleStatus xmlns="">
<dtVehicleStatus diffgr:id="dtVehicleStatus1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<Device_x0020_No>805251</Device_x0020_No>
<GMT_x0020_Date_x002F_Time>2020-07-10T06:00:55+03:00</GMT_x0020_Date_x002F_Time>
<Latitude>41.070751</Latitude>
<Longitude>29.000586</Longitude>
<Speed>0</Speed>
<Address>Cemal Sururi Sk., Gülbahar Mh., Şişli, İstanbul, Türkiye</Address>
<Building_x0020__x002F__x0020_Region/>
<Height>205</Height>
</dtVehicleStatus>
<dtVehicleStatus diffgr:id="dtVehicleStatus2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
<Device_x0020_No>805252</Device_x0020_No>
<GMT_x0020_Date_x002F_Time>2020-07-08T13:33:24+03:00</GMT_x0020_Date_x002F_Time>
<Latitude>41.071037</Latitude>
<Longitude>29.00054</Longitude>
<Speed>7.86</Speed>
<Address>Şat Otopark, Çamlı Sk., Gülbahar Mh., Şişli, İstanbul, Türkiye</Address>
<Building_x0020__x002F__x0020_Region/>
<Height>151</Height>
</dtVehicleStatus>
<dtVehicleStatus diffgr:id="dtVehicleStatus3" msdata:rowOrder="2" diffgr:hasChanges="inserted">
<Device_x0020_No>805253</Device_x0020_No>
<GMT_x0020_Date_x002F_Time>2020-07-10T05:31:43+03:00</GMT_x0020_Date_x002F_Time>
<Latitude>41.071087</Latitude>
<Longitude>29.000429</Longitude>
<Speed>6.31</Speed>
<Address>Şat Otopark, Çamlı Sk., Gülbahar Mh., Şişli, İstanbul, Türkiye</Address>
<Building_x0020__x002F__x0020_Region/>
<Height>103</Height>
</dtVehicleStatus>
</tblVehicleStatus>
</diffgr:diffgram>
</DataSet>