我有一个ASMX web服务内部的两个方法是这样的:错误的WebService ASMX有不同的返回类型
[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: Index was outside the bounds of the array.
at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
但是当我更改返回类型Method_2到void,一切工作正常。 为什么发生?我怎样才能解决它而不改变返回类型?
UPDATE 有这两种方法的另一个区别:一个recive一类作为参数和其他不recive任何参数。当我从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;
}
是这样工作的,但我仍然不知道为什么会发生。
什么是此错误的堆栈跟踪?什么线投掷它? – mason
它现在在那里。我编辑问题 – Salatiel