作者:iuang | 来源:互联网 | 2023-09-02 18:59
存在问题:想实现这样的方式来访问webservice,类似(可以外网访问):http:www.webservicex.netglobalweather.asmxGetCit
想实现这样的方式来访问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的 ... 内增加如下元素标签:
-
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