技术开发 频道

ASP.NET AJAX之内部揭秘(1)

糟糕的调用会使好的调用超时

如果有两个HTTP调用不知何故执行了很长的时间,那么这两个糟糕的调用也将会使好的调用超时,同时这两个调用会进入队列。这里就有一个例子:

Collapse function TestTimeout() { debug.trace("--Start--"); TestService.set_defaultFailedCallback( function(result, userContext, methodName) { var timedOut = result.get_timedOut(); if( timedOut ) debug.trace( "Timedout: " + methodName ); else debug.trace( "Error: " + methodName ); }); TestService.set_defaultSucceededCallback( function(result) { debug.trace( result ); }); TestService.set_timeout(5000); TestService.HelloWorld("Call 1"); TestService.Timeout("Call 2"); TestService.Timeout("Call 3"); TestService.HelloWorld("Call 4"); TestService.HelloWorld("Call 5"); TestService.HelloWorld(null); // 这句将导致错误 }

服务端的web service也非常简单:

[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class TestService : System.Web.Services.WebService { public TestService () { // 如果使用设计的组件,请取消注释以下行 // InitializeComponent(); } [WebMethod][ScriptMethod(UseHttpGet=true)] public string HelloWorld(string param) { Thread.Sleep(1000); return param; } [WebMethod][ScriptMethod(UseHttpGet=true)] public string Timeout(string param) { Thread.Sleep(10000); return param; } }

我调用了服务端的名为“Timeout”的方法,它不会做任何事情,而只是等待一个较长的时间以使调用超时。之后再调用一个不会超时的方法。但是你猜猜输出的是什么:

0
相关文章