使用Post调用以asmx形式提供的webservice时,在本机调试没有调用问题。一旦部署至服务器后会提示如下信息:
<html><head><title>因 URL 意外地以“/GetCertByToken”结束,请求格式无法识别。</title><meta name="viewport" content="width=device-width" /><style>body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}.marker {font-weight: bold; color: black;text-decoration: none;}.version {color: gray;}.error {margin-bottom: 10px;}.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }@media screen and (max-width: 639px) {pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }}@media screen and (max-width: 479px) {pre { width: 280px; }}</style></head><body bgcolor="white"><span><H1>“/”应用程序中的服务器错误。<hr width=100% size=1 color=silver></H1><h2> <i>因 URL 意外地以“/GetCertByToken”结束,请求格式无法识别。</i> </h2></span><font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "><b> 说明: </b>执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。<br><br><b> 异常详细信息: </b>System.InvalidOperationException: 因 URL 意外地以“/GetCertByToken”结束,请求格式无法识别。<br><br><b>源错误:</b> <br><br><table width=100% bgcolor="#ffffcc"><tr><td><code>执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。</code></td></tr></table><br><b>堆栈跟踪:</b> <br><br><table width=100% bgcolor="#ffffcc"><tr><td><code><pre>[InvalidOperationException: 因 URL 意外地以“/GetCertByToken”结束,请求格式无法识别。]System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +675System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +259System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +81System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +375System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128
</pre></code></td></tr></table><br><hr width=100% size=1 color=silver><b>版本信息:</b> Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.7.3282.0</font></body>
</html>
解决方案:
修改web.config文件,增加如下内容即可。
<system.web><webServices><protocols><add name="HttpGet" /><add name="HttpPost" /> <add name="Unknown" /><add name="HttpSoap" /></protocols></webServices></system.web>