来自 WinRT Metro 的 Web 服务 [英] Web Services from WinRT Metro
问题描述
我正在尝试使用 Windows 8 Xaml/C# Metro 应用程序中的 DictService Web 服务,但遇到了问题.
I am trying to use the DictService web service from a Windows 8 Xaml / C# Metro application and am having issues.
DictService 的 WSDL 是 http://services.aonaware.com/DictService/DictService.asmx?WSDL
The WSDL for the DictService is http://services.aonaware.com/DictService/DictService.asmx?WSDL
但是当我添加服务引用时,我收到以下警告:
But when I add the service reference I get the following warning:
自定义工具警告:地址为http://services.aonaware.com/DictService/DictService.asmx"的端点DictServiceSoap12"与 Windows Metro 风格应用程序不兼容.跳过...
Custom tool warning: Endpoint 'DictServiceSoap12' at address 'http://services.aonaware.com/DictService/DictService.asmx' is not compatible with Windows Metro style apps. Skipping...
关于如何解决这个问题并使用 Metro Applciation 中的 DictService 有什么想法吗?
Any ideas on how I can get past this and use the DictService from a Metro Applciation?
推荐答案
我想出了如何做到这一点,所以我想我不妨发布一些代码并回答我自己的问题......也可能对以下方面有用对从 Windows 8 Metro 应用调用 XML 网络服务感兴趣的任何其他人.
I worked out how to do this, so I thought I might as well post a bit of code and answer my own question... might also be useful for anyone else who is interested in calling an XML webservice from a windows 8 metro app.
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; }
}
这篇关于来自 WinRT Metro 的 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!