我找不到如何从此代码中替换 Webclient。
什么是新的命名空间以及在 Windows 8 中创建它的方式...... Win 8 dev 的新功能。
任何提示或帖子都会有所帮助,或者下面的任何代码。
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
Uri url2 = new Uri("http://www.buscms.com/api/XmlEntities/v1/stops.aspx", UriKind.Absolute);
client.DownloadStringAsync(url2);
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
if (e.Result != null)
{
XDocument doc = XDocument.Parse(e.Result);
XNamespace ns = "http://schemas.datacontract.org/2004/07/BusExpress.ClassLibrary";
var routeNames = (from n in doc.Descendants(ns + "ArrayOfStop")
select new RootContainer2
{
Departures = (from s in n.Elements(ns + "Stop")
select new Departures
{
StopName = s.Element(ns + "StopName").Value,
}).ToList()
}).Single();
listBox2.ItemsSource = routeNames.Departures;
}
}
}