首页 / 脚本样式 / Ajax / 客户端访问Web Service方法的一个细节
客户端访问Web Service方法的一个细节2011-09-06之前遇到一个要求,需要能够取消一个正在进行中的Web Service。这也是我第一次遇到这个功能,不过不难,我想。既然ASP.NET AJAX的客户端与服务器端通信完全通过Microsoft AJAX Library的异步通信层进行,那么我们只要得到正在请求Web Service的Sys.Net.WebRequest对象,调用其abort方法就可以了。但是究竟应该如何得到这个对象呢?于是我粗略地阅读了一下代码。首先假设有如下的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);
...