我有一個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