When I call the my service as below the XML elements TruckName and Website are null? Clearly the elements are poupulated in the XML on the web page (see xml below). I believe its related to the ArrayOf element being first? Below is also the code from my console app calling the method GetInfo(). Do I need to get rid of the ArrayOfFoodTruck element? If so whats the easiest way. thanks to all in advance..
- <ArrayOfFoodTruck xmlns="http://schemas.datacontract.org/2004/07/WCFServiceLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
- <FoodTruck>
<Company i:nil="true" />
<DayOfWeek i:nil="true" />
<Location i:nil="true" />
<TimeOfDay i:nil="true" />
<TruckID>0</TruckID>
<TruckName>Truck 87</TruckName>
<Website>http://www.test.com</Website>
</FoodTruck>
- <FoodTruck>
<Company i:nil="true" />
<DayOfWeek i:nil="true" />
<Location i:nil="true" />
<TimeOfDay i:nil="true" />
<TruckID>0</TruckID>
<TruckName>Bon Me</TruckName>
<Website>http://www.test.com</Website>
</FoodTruck>
</ArrayOfFoodTruck>
This is the call from my console app..
static void GetInfo()
{
XElement rootXml = XElement.Load("http://localhost:5150/getnames");
var FoodTruck = from C in rootXml.Elements()
select new { TruckName = (string)C.Element("TruckName"), WebSite = (string)C.Element("Website") };
foreach (var x in FoodTruck)
Console.WriteLine("{0}\r\n{1}", x.TruckName, x.WebSite);
Console.ReadKey();
}
I guess you have problem with the namespace
–EDIT– OR