WebService支持Post和Get方法

< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>

在WebService的测试页面,你看到了什么?SOAP1.1/SOAP1.2/HTTP POST三种方法的测试页面,但是事实上,此时你用post方法是无法访问这个webservice的,更不用说get了。.net 2.0下的所有新建webservice默认关闭了这两种方法,是为了安全考虑。

但是我们有的时候不得不使用这两种方法,特别是get方法,几乎由一切软件和编程方法支持,并且可以穿越几乎所有的防火墙(除非连web访问都不让,那是中情局吧……)。那么如何让部署起来的webservice支持这种方法呢?

在webservice的目录下添加Web.config文件(如果已经存在就修改之),最简单的情况,我们需要这样的文件:

如果你已经有了VS生成的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.web>
</configuration>

如果你已经有了VS生成的Web.config,那么只需要修改或添加这么一段

<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>

原文地址:https://www.cnblogs.com/netcorner/p/2911914.html