我在ASMX Web服务中有两个方法,如下所示:
import ogr
当我尝试使用AJAX调用其中一个方法时,它会返回以下错误:
System.IndexOutOfRangeException:索引超出了数组的范围 在System.Web.Services.Protocols.HttpServerType..ctor(类型类型)
在System.Web.Services.Protocols.HttpServerProtocol.Initialize()
在System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type,HttpContext context,HttpRequest request,HttpResponse response,Boolean& abortProcessing)
但是当我将 Method_2 的返回类型更改为 void 时,一切正常。 为什么会这样?如何在不更改返回类型的情况下修复它?
更新 这两种方法之间还有另一个区别:一种是将一个类作为参数,另一种不重复任何参数。当我从 Method_2 中删除参数时,它也可以正常工作。
更新2 我将 Method_2 更改为:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class TestWs: WebService
{
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false)]
public void Method_1()
{
//Do Something
}
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false)]
public long Method_2(ParameterClass paramClass)
{
return 0;
}
}
它以这种方式工作,但我仍然不知道它为什么会发生。
答案 0 :(得分:0)
似乎这篇文章可能会对您有所帮助,将复杂参数作为Web服务的输入会产生问题。