Web Services from WinRT Metro

 ̄綄美尐妖づ 提交于 2019-12-11 03:54:22

问题


I am trying to use the DictService web service from a Windows 8 Xaml / C# Metro application and am having issues.

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:

Custom tool warning: Endpoint 'DictServiceSoap12' at address 'http://services.aonaware.com/DictService/DictService.asmx' is not compatible with Windows Metro style apps. Skipping...

Any ideas on how I can get past this and use the DictService from a Metro Applciation?


回答1:


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; }
    }


来源:https://stackoverflow.com/questions/10470543/web-services-from-winrt-metro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!