WebClient类不存在于Windows中8 [英] WebClient class doesn't exist in Windows 8

查看:226
本文介绍了WebClient类不存在于Windows中8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用一个HTTP web服务,我已经开发了WP7的应用程序。

I want to use a HTTP webservice, and I've already developed an app for wp7.

我用WebClient类,但我不能用它为Windows 8(错误:类型或命名空间无法找到)

I use the WebClient class, but I can not use it for windows 8 ("error: type or namespace can not be found").

还有什么我可以使用?

What else can I use?

您可以给我提供code的样本?

Can you provide me a sample of code?

Microsoft是否有一个网站,以帮助在命名空间不存在?

Does Microsoft have a site to help when a namespace don't exist?

推荐答案

选项1:HttpClient的,如果你不需要确定性进度通知,这是你想要使用的。例子。

Option 1 : HttpClient if you don't need deterministic progress notification this is what you want use. Example.

public async Task<string> MakeWebRequest()
{
       HttpClient http = new System.Net.Http.HttpClient();
       HttpResponseMessage response = await http.GetAsync("http://www.example.com");
       return await response.Content.ReadAsStringAsync();
}

选项2:当你需要进度通知您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.backgroundtransfer.downloadoperation.aspx\"相对=nofollow> DownloadOperation 或<一个href=\"http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.backgroundtransfer.backgrounddownloader.aspx\"相对=nofollow> BackgroundDownloader 。 MSDN上这样品是一个良好的开端。

Option 2: When you need progress notifications you can use DownloadOperation or BackgroundDownloader. This sample on MSDN is a good start.

选项3:既然你提到的Web服务,如果它返回的XML可以使用的 XmlDocument.LoadFromUriAsync 这将返回的XML文档。示例

Option 3: Since you mentioned web service and if it is returning XML you can use XmlDocument.LoadFromUriAsync which will return you an XML document. Example

public async void DownloadXMLDocument()
{
      Uri uri = new Uri("http://example.com/sample.xml");
      XmlDocument xmlDocument = await XmlDocument.LoadFromUriAsync(uri);
      //do something with the xmlDocument.
}

当你在地铁Net框架进行开发相比桌面版的限制。如果你看到命名空间没有发现错误,通常是由于这一事实。这 链路在MSDN有命名空间,类可用于地铁的列表中。

When you are developing for metro .Net framework will be limited compared to the desktop version. If you see namespace not found error it is usually due to this fact. This link on the MSDN has the list of namespaces, classes available for metro.

这篇关于WebClient类不存在于Windows中8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆