当消费WebService时,我得到了以下错误:

URL意外以/myMethodName结尾,请求格式无法识别

如何解决这个问题?


当前回答

极好的。

情况2 -同样的问题可以出现)在我的情况下,问题是由于以下一行:

<webServices>
  <protocols>
    <remove name="Documentation"/>
  </protocols>
</webServices>

它在服务器上工作得很好,因为直接调用webservice函数——但是如果你在调试环境中直接从。net运行服务,并且想要手动测试运行该函数,则会失败。

其他回答

在这个网站上找到了一个解决方案

你所需要做的就是在你的web.config中添加以下内容

<configuration>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
  </system.web>
</configuration>

来自微软的更多信息

确保你使用了正确的方法:Post/Get,正确的内容类型和正确的参数(数据)。

$.ajax({
    type: "POST",
    url: "/ajax.asmx/GetNews",
    data: "{Lang:'tr'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) { generateNews(msg); }
})

极好的。

情况2 -同样的问题可以出现)在我的情况下,问题是由于以下一行:

<webServices>
  <protocols>
    <remove name="Documentation"/>
  </protocols>
</webServices>

它在服务器上工作得很好,因为直接调用webservice函数——但是如果你在调试环境中直接从。net运行服务,并且想要手动测试运行该函数,则会失败。

为了记录,当我将一个旧应用程序从一个服务器移动到另一个服务器时,我得到了这个错误。我添加了<add name="HttpGet"/> <add name="HttpPost"/>元素到web。Config,它将错误更改为:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at BitMeter2.DataBuffer.incrementCurrent(Int64 val)
   at BitMeter2.DataBuffer.WindOn(Int64 count, Int64 amount)
   at BitMeter2.DataHistory.windOnBuffer(DataBuffer buffer, Int64 totalAmount, Int32 increments)
   at BitMeter2.DataHistory.NewData(Int64 downloadValue, Int64 uploadValue)
   at BitMeter2.frmMain.tickProcessing(Boolean fromTimerEvent)

为了修复这个错误,我必须添加ScriptHandlerFactory行到web.config:

  <system.webServer>
    <handlers>
      <remove name="ScriptHandlerFactory" />
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </handlers>
  </system.webServer>

为什么在一个服务器上没有这些行,而在另一个服务器上没有,我不知道。

在html中,你必须将调用包含在一个带有GET的表单中

<a href="/service/servicename.asmx/FunctionName/parameter=SomeValue">label</a>

您还可以使用POST,其操作是web服务的位置,并通过输入标记输入参数。

还有SOAP和代理类。