Ajax调用WebService之System.InvalidOperationException

           使用Ajax调用asp.net中的web service,你可能遇到这样的Exception:

System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/MethodName'
 
      .net中的WebService支持三种协议HTTPGET, HTTPPOST 和 SOAP。默认的SOAP是支持的,当你使用这样的格式时:
domain/webservice.asmx/methodname [Get/Post] 做的则是GET OR POST。

          怎么解决呢,修改WEB.CONFIG文件如下配置节:

   1:      <webServices>
   2:        <protocols>
   3:          <add name="HttpSoap"/>
   4:          <add name="HttpGet"></add>
   5:          <add name="HttpPost"></add>
   6:        </protocols>
   7:      </webServices>

       增加GET和POST结点就可以了。当然你愿意,可以修改Machine.config。

希望这篇POST对您有帮助。


作者:Petter Liu
出处:http://www.cnblogs.com/wintersun/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-Petter Liu Blog

原文地址:https://www.cnblogs.com/wintersun/p/1746060.html