过去,我曾有过调用WCF服务或ASMX服务的经验,您只需将服务引用添加到.svc或.asmx URL,然后它会为您生成代理,然后您便具有了智能感知来调用这些方法。
非.net Web服务是否相同?
我叫这个
http://www.earthtools.org/webservices.htm
从Winrt应用程序中的C#代码中获取信息,但是我只是不知道如何
最佳答案
如果您有WSDL,则可以添加对该服务的引用。但是在这里您尝试调用REST服务。
您需要发送发帖请求并将响应发送为:
private const string BASE_URL = "http://www.earthtools.org/timezone";
private const string REQUEST_URL_FORMAT = "{0}/{1}/{2}";
public timezone GetTimeZone(double latitude, double longitude)
{
var uriString = String.Format(REQUEST_URL_FORMAT, BASE_URL, latitude, longitude);
var requestUri = new Uri(uriString);
var request = WebRequest.Create(requestUri);
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
var ser = new XmlSerializer(typeof (timezone));
var result = (timezone) ser.Deserialize(responseStream);
return result;
}
}
}
here中的示例。
关于c# - 如何调用不在.NET中开发的Web服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10976367/