2007-08-03

客户端访问Web Service方法的一个细节

来源: 老赵点滴 作者: 赵劼   评论 0 条
 

  之前碰到一个要求,需要能够取消一个正在进行中的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,

        


共3页: 上一页 1 [2] [3] 下一页
(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:如何让WebServer返回指定XML内容  
下一篇:简化XML读写-用XPath等查询定义简化DOM编码
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号