May 24
在WebService的测试页面,你看到了什么?SOAP1.1/SOAP1.2/HTTP POST三种方法的测试页面,但是事实上,此时你用post方法是无法访问这个webservice的,更不用说get了。.net 2.0下的所有新建webservice默认关闭了这两种方法,是为了安全考虑。
但是我们有的时候不得不使用这两种方法,特别是get方法,几乎由一切软件和编程方法支持,并且可以穿越几乎所有的防火墙(除非连web访问都不让,那是中情局吧……)。那么如何让部署起来的webservice支持这种方法呢?
在webservice的目录下添加Web.config文件(如果已经存在就修改之),最简单的情况,我们需要这样的文件:
< ?xml version="1.0"?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system .web> <compilation defaultLanguage="c#" debug="true"/> <webservices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webservices> </system> </configuration>
如果你已经有了VS生成的Web.config,那么只需要修改或添加这么一段
<webservices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webservices>
这样就行了,你就可以在测试页面看到多出来一种HTTP GET的方法示例,并且也可以在程序中使用了
Related posts:
Recent Comments