问题
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