文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>asp.net2.0中异步调用WebService(异步页)_Asp.Net开发技巧

asp.net2.0中异步调用WebService(异步页)_Asp.Net开发技巧

时间:2010-09-16  来源:蔚蓝的大海

由于asp2.0提供了异步页的支持使异步调用WebService的性能有了真正的提升。
使用异步页,首先要设置Async="true",异步页是在Prerender和PrerenderComplete事件间加入Begin,end异步方法实现的,Begin和End方法属于不同的线程。
WS异步页的实现有两种方式:
1、使用等待方法实现异步
通用类,封装了WS
/**//// <summary>
        /// 使用等待方法实现异步
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private Account account;
        private string username;
        public Account Account
        {
            get { return account; }
            set { account = value; }
        }
        public string Username
        {
            get { return username; }
            set { username = value; }
        }
        public IAsyncResult BeginAsyncGetAccount(object sender, EventArgs e, AsyncCallback cb, object state)
        {
          
            return vb.BeginGetAccountbyName(username,cb,state);
        }
        public void EndAsyncGetAccount(IAsyncResult ar)
        {
            account = vb.EndGetAccountbyName(ar);
        }

          /**//// <summary>
        /// 使用事件驱动的异步
        /// </summary>
        /// <param name="username"></param>
        public void GetAccountCompleted(Object source, VB.GetAccountbyNameCompletedEventArgs e)
        {
            account = e.Result;
        }
        public void AsGetAccount(string username)
        {
                      vb.GetAccountbyNameCompleted += new GetAccountbyNameCompletedEventHandler(GetAccountCompleted);
            vb.GetAccountbyNameAsync(username)
           
        }调用方法
 protected void Page_Load(object sender, EventArgs e)
    {
        this.PreRenderComplete += new EventHandler(Page_PreRenderComplete);
        b.Username = "dinghao";
      
        AddOnPreRenderCompleteAsync(b.BeginAsyncGetAccount, b.EndAsyncGetAccount);
    }
    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        //异步调用结束
        VB.Account a = b.Account;
        AccountIf ai = new AccountIf(a);
        ais[0] = ai;
        GridView1.DataSource = ais;
        GridView1.DataBind();
    }由于AddOnPreRenderCompleteAsync的两个委托都是Void类型,所以在通用类中要加入有返回值的属性如:Account供主调方法使用,另外委托中没有异步方法的参数信息,要加入参数的属性如:Username
2、事件驱动的异步(2.0新增)
调用方法:
protected void Page_Load(object sender, EventArgs e)
    {
        this.PreRenderComplete += new EventHandler(Page_PreRenderComplete);
        b.AsGetAccount("dinghao");
    
    }
    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        //异步调用结束
        VB.Account a = b.Account;
        AccountIf ai = new AccountIf(a);
        ais[0] = ai;
        GridView1.DataSource = ais;
        GridView1.DataBind();
    }这种调用方式,用的是*Completed事件,在*Async完成时触发,这种调用方式可以
省去Account,Username属性,用起来比较简单

http://bluewater.cnblogs.com/archive/2006/06/20/430758.html


hd best buycar lcd monitorwisp my areausb 2.0 speed specificationconnect dell tvnintendo ds games circuit citygcs632u 2 port kvm switchultra320 scsi cabledvr card reviewrealtek network adapter driver1394 firewire usbsony mp4 converterplaca de video agp 4xcable audio jack rcainternet connection problem vistaethernet cord adapterstarget credit card problemsmake 9 pin serial cablecable wire installationsony universal remote controlverbatim flash drive reviewcomponent audio videobest pc enclosuremicrosoft micedoes hdmi transmit audiovista system diagnosticsconnecting wiis over the internethigh power smt ledverizon aircardpcmcia cardscoaxial splitterschannel cbs cablelcd computer monitor buying guidelcd testdell 1184 wireless broadband routermotivational speaker jobsoptical cable surround soundflash drive clearanceanalog lcd monitor couponscomcast cable box rentaldriver sound cardbest buy external modemnytregal wikispore opinionsusb wirelss adaptorps3 hdmi til scartoti6828 flash disk usb devicdwl g710 passwordwii hd cable review

Replica lv Hangbags

Replica Hangbags

Hangbags

replica handbags

replica handbags

replica handbags

replica handbags

handbags

replica handbags replica handbags replica handbags replica handbags replica handbags

usb cable

usb cable

usb cable

usb cable

usb flash drives

usb flash drives

usb flash drives usb flash drives usb flash drives usb flash drives USB Connector USB Connector USB Connector USB Connector USB Connector USB Connector
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载