我們從客戶端調用Asp.Net ajax Web服務。所以JavaScript函數的調用如下所示:如何解決:在Ajax WebService中會話超時時InvalidOperationException調用
//該函數用於更改服務器端狀態對象併爲案例樹設置所選節點。
function JSMethod(caseId, url)
{
Sample.XYZ.Method(param1, param2, OnMethodReturn);
}
function OnMethodReturn(result)
{
var sessionExpiry = CheckForSessionExpiry(result);
var error = CheckForErrors(result);
... process result
}
而就在「.asmx.cs」文件服務器端: 命名空間樣品
[ScriptService]
class XYZ : WebService
{
[WebMethod(EnableSession = true)]
public string Method(string param1, string param2)
{
if (SessionExpired())
{
return sessionExpiredMessage;
}
.
.
.
}
}
該網站設置爲使用基於表單的身份驗證。現在,如果會話已過期,然後調用了JavaScript函數「JSMethod」,則 將獲得以下錯誤: Microsoft JScript運行時錯誤:Sys.Net.WebServiceFailedException:服務器方法'Method'失敗,並顯示以下錯誤:System .InvalidOperationException - 身份驗證失敗。
此異常的方法「功能SYS $ NET $ WebServiceProxy $調用」文件「的ScriptResource.axd」提出:
function Sys$Net$WebServiceProxy$invoke
{
.
.
.
{
// In debug mode, if no error was registered, display some trace information
var error;
if (result && errorObj) {
// If we got a result, we're likely dealing with an error in the method itself
error = result.get_exceptionType() + "-- " + result.get_message();
}
else {
// Otherwise, it's probably a 'top-level' error, in which case we dump the
// whole response in the trace
error = response.get_responseData();
}
// DevDiv 89485: throw, not alert()
throw Sys.Net.WebServiceProxy._createFailedError(methodName, String.format(Sys.Res.webServiceFailed, methodName, error));
}
所以問題是,引發異常,甚至之前的「法」是調用時,在創建Web代理期間發生異常。有關如何解決此問題的任何想法
-1:靜態僅供PageMethods – 2010-08-06 05:01:12