【发布时间】:2017-11-03 03:30:18
【问题描述】:
我在 ASMX Web 服务中有两种方法,如下所示:
[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;
}
}
当我尝试使用 AJAX 调用其中一种方法时,它返回以下错误:
System.IndexOutOfRangeException:索引超出了数组的范围。
在 System.Web.Services.Protocols.HttpServerType..ctor(类型类型)
在 System.Web.Services.Protocols.HttpServerProtocol.Initialize()
在 System.Web.Services.Protocols.ServerProtocolFactory.Create(类型类型、HttpContext 上下文、HttpRequest 请求、HttpResponse 响应、Boolean& abortProcessing)
但是当我将 Method_2 的返回类型更改为 void 时,一切正常。 为什么会这样?如何在不更改返回类型的情况下修复它?
更新 这两种方法之间还有另一个区别:一种接收类作为参数,另一种不接收任何参数。当我从 Method_2 中删除参数时,它也可以工作。
更新 2 我将 Method_2 更改为:
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = false)]
public long Method_2(string paramString)
{
ParameterClass pClass = (new JavaScriptSerializer()).Deserialize<ParameterClass>(paramString);
//Do Something.
return 0;
}
它是这样工作的,但我仍然不知道它为什么会发生。
【问题讨论】:
-
这个错误的堆栈跟踪是什么?哪条线抛出它?
-
它现在就在那里。我编辑问题
标签: c# asp.net web-services asmx