我们从客户端调用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