我想出了如何做到这一点,所以我想我不妨发布一些代码并回答我自己的问题......对于任何有兴趣从 Windows 8 Metro 应用程序调用 XML Web 服务的人来说也可能有用。
public async Task<List<WordDefinition>> GetDefinitions(string word)
{
try
{
HttpClient httpclient = new HttpClient();
var dictService = await httpclient.GetStringAsync("http://services.aonaware.com/DictService/DictService.asmx/DefineInDict?DictId=wn&word=" + word);
XNamespace ns = "http://services.aonaware.com/webservices/";
var dictInfo = XElement.Parse(dictService);
var definitions = dictInfo.Descendants(ns + "Definitions");
List<WordDefinition> defInfo = (from definition in definitions.Descendants(ns + "Definition")
select new WordDefinition
{
Word = definition.Element(ns + "Word").Value,
Definition = definition.Element(ns + "WordDefinition").Value
}).ToList<WordDefinition>();
return defInfo;
}
catch (Exception ex)
{
return new List<WordDefinition>();
}
}
public class WordDefinition
{
public string Word { get; set; }
public string Definition { get; set; }
}