导航

通过URL传参调用webservice(转)

Posted on 2011-12-13 23:48  寒宵飞飞  阅读(3143)  评论(0编辑  收藏  举报

存在问题

想实现这样的方式来访问webservice,类似(可以外网访问):http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=China
我自己定义的webservice中的方法代码如下:
C# code
[WebMethod] public string HelloWorld(string name) { return name; }

希望能够通过:http://localhost:4109/Gridview/HelloWorld.asmx/HelloWorld?name=123   直接调用webservice

 

 

 

处理办法如下:

 
在web站点的web.config的 <system web>... </system web>内增加如下元素标签:
XML code
<webServices> <protocols> <add name="HttpPost" /> <add name="HttpGet" /> <add name="HttpSoap" /> <add name="Documentation" /> </protocols> </webServices>

原理剖析:
通过http请求访问webservice有三种方式,在ie中输入url并传参的方式属于http-get方式。通过增加web.config配置,实现允许get请求即可。

 

 

 

 

 

 

 

转自:http://blog.csdn.net/cryeyes/article/details/4730182