之前碰到一个要求,需要能够取消一个正在进行中的Web Service。这也是我第一次碰到这个功能,不过不难,我想。既然ASP.NET AJAX的客户端与服务器端通信完全通过Microsoft AJAX Library的异步通信层进行,那么我们只要得到正在请求Web Service的Sys.Net.WebRequest对象,调用其abort方法就可以了站长资讯网欢迎您(www.chinahtml.com)。但是究竟应该如何得到这个对象呢?于是我粗略地阅读了一下代码。
首先假设有如下的Web Service方法定义(DemoService.asmx):
[ScriptService] public class DemoService : System.Web.Services.WebService { [WebMethod] public string DemoMethod() { return "Hello World"; } }
访问DemoService.asmx/jsdebug(或者将其使用ScriptManager引用到页面中之后)就能够得到如下的代理(片断、经过排版)类。
var DemoService = function()
{
DemoService.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
}
DemoService.prototype =
{
DemoMethod:function(succeededCallback, failedCallback, userContext)
{
return this._invoke(
DemoService.get_path(),
'DemoMethod',
false,
{},
succeededCallback,
failedCallback,
userContext);
}
}
DemoService.registerClass('DemoService',Sys.Net.WebServiceProxy);
...显然,这个代理类继续了Sys.Net.WebServiceProxy类,于是我就把目光转向了其中的_invoke方法:
function Sys$Net$WebServiceProxy$_invoke( servicePath, methodName, useGet, params, onSuccess, onFailure, userContext) { // validation omitted ... return Sys.Net.WebServiceProxy.invoke( servicePath, methodName, useGet, params, onSuccess, onFailure, userContext,
评论加载中…
![]() |