如何在Web服务下面使用并在C#中使用 [英] how to use below web service and consume in c#

查看:52
本文介绍了如何在Web服务下面使用并在C#中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi to alll ...
我有一个疑问..
我有像这样的网络服务链接:
http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo ..
如何在C#中使用此Web服务...
我试过这样的方式:右键单击项目,然后选择添加Web引用",然后打开添加Web引用"窗口.
Internet Explorer无法从api.geonames.org下载cityJSON,并且Internet Explorer无法打开此互联网站点.请求的站点不可用或找不到.请稍后再试.....

如果有人知道上述问题,请让我知道..这对我来说非常紧急,需要充分...

hi to alll...
i have a doubt..
i have webservice link like:
http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo..
how to consume this webservice in c#...
i tried like this: rightclick on project and select Add webreference then Add web refrence window open.. and i copied the above link and enter,error came like that..

Internet Explorer cannot download citiesJSON from api.geonames.org and Internet Explorer was not able to open this internetsite.the Requested site is either unavailable or cannot be found.pls try again later.....

If any body knows for the above problem pls let me know..its very urgent for me and do the need full...

推荐答案

我想您正在尝试调用基于REST的服务,该服务将返回Json数据.

首先检查有效的REST服务网址.如果您的REST服务网址正确,请尝试通过以下代码调用服务.

I guess you are trying to Call REST based service which will return Json Data.

Firstly check for valid REST Service Url. If your REST Service url is correct then try calling service by below code.

string apiUrl = "YourFullServiceUrl";
Uri address = new Uri(apiUrl);

// Create the web request 
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(address) as System.Net.HttpWebRequest;
request.Method = "GET";
request.ContentType = "text/json";

using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
{
// Get the response stream 
System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());

string strOutput = reader.ReadToEnd();
}


这篇关于如何在Web服务下面使用并在C#中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆