Before writing this question, I tried this, this and this method. I spent the whole day on it and could not get the result.
I have my own REST API which returns a serialized List<T>
in XML file
[ActionName("planes")]
[HttpGet]
public IEnumerable<Planes> GetPlanes()
{
using (DB_A5vehiclesEntities entities = new DB_A5_vehiclesEntities())
{
return entities.Planes.ToList();
}
}
Generated XML file looks like this (link to xml file):
<ArrayOfPlanes xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/VehicleDataAccess">
<Planes>
<FirstFlyYear>1932</FirstFlyYear>
<Id>18</Id>
<Name>18</Name>
//other values
</Planes>
//other items
My code:
IList<Plane> myList = null;
string xml = @"http://bo7145907-001-site2.ftempurl.com/wtvapi/vehicles/planes";
XmlSerializer serializer = new XmlSerializer(typeof(List<Plane>));
using (StringReader reader = new StringReader(xml))
{
myList = serializer.Deserialize(reader) as List<Plane>;
}
textMessage = FindViewById<TextView>(Resource.Id.message);
}
And i get the error: System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1
All I want is just connect to API, deserialize XML and get List<T>
with all XML elements.
How to do it right?