c# - WinRT Metro 的 Web 服务

标签 c# web-services windows-8

我尝试从 Windows 8 Xaml/C# Metro 应用程序使用 DictService Web 服务,但遇到了问题。

DictService 的 WSDL 是 http://services.aonaware.com/DictService/DictService.asmx?WSDL

但是当我添加服务引用时,我收到以下警告:

自定义工具警告:地址“http://services.aonaware.com/DictService/DictService.asmx”处的端点“DictServiceSoap12”与 Windows Metro 风格应用程序不兼容。正在跳过...

关于如何克服这个问题并使用 Metro 应用程序中的 DictService 有什么想法吗?

最佳答案

我想出了如何做到这一点,所以我想我不妨发布一些代码并回答我自己的问题...对于有兴趣从 Windows 8 调用 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; }
    }

关于c# - WinRT Metro 的 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10470543/

相关文章:

windows - 帧到视频 - Windows 8 中的图像处理(仅限 WinRT)

xaml - 在 Windows Store Apps/Metro XAML 中将 WebView 设置为自动高度

c# - 无法从 Task<> 隐式转换类型

c# - 为什么 Predicate<> 是密封的?

asp.net - 使用 JQuery 访问 ASP.net Web 服务时出错 - JSONP

future 某个时间的Java运行事件

c# - BinaryFormatter 和反序列化。如何在流的末尾停止?

c# - 内存中对象的大小

c# - NuGet 包 : how to add references to webservices?

c# - 为什么我的页面失去焦点?