• 异步调用开发应用总结(WCF)


    上一篇随笔的异步调用是方法的异步调用实现,WCF的异步调用有自己的实现逻辑(一些方法和调用过程.net已经制定好)

    WCF异步调用示例:

    客户端调用:

                AsyncManageAgent clientAgent = this.Command as AsyncManageAgent;
                clientAgent.GetNameAsync(Code, userState);
                clientAgent.GetNameCompleted += delegate(object sender, Agent.GetNameCompletedEventArgs args)
                {

                    this.GetNameCompleted(this, new GetNameCompletedEventArgs(args.results,args.Error,args.Cancelled,args.UserState));
                };

    WCF代理类(异步调用)

            private System.IAsyncResult OnBeginGetName(object[] inValues, System.AsyncCallback callback, object asyncState)
            {
                string Code = inValues[0].ToString();
                return this.BeginGetName(Code, callback, asyncState);
            }

            //onEnd
            private object[] OnEndGetName(System.IAsyncResult result)
            {
                string retVal = this.EndGetName(result);
                return new object[] {
                        retVal};
            }

            //OnCompleted
            private void OnGetNameCompleted(object state)
            {
                if ((this.GetNameCompleted != null))
                {
                    InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                    this.GetNameCompleted(this, new GetNameCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
                }
            }
            //Async方法
            public void GetNameAsync(string Code)
            {
                this.GetNameAsync(Code, null);
            }

            public void GetNameAsync(string Code, object userState)
            {
                if ((this.onBeginGetNameDelegate == null))
                {
                    this.onBeginGetNameDelegate = new BeginOperationDelegate(this.OnBeginGetName);
                }
                if ((this.onEndGetNameDelegate == null))
                {
                    this.onEndGetNameDelegate = new EndOperationDelegate(this.OnEndGetName);
                }
                if ((this.onGetNameCompletedDelegate == null))
                {
                    this.onGetNameCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetNameCompleted);
                }
                base.InvokeAsync(this.onBeginGetNameDelegate, new object[] {
                            Code}, this.onEndGetNameDelegate, this.onGetNameCompletedDelegate, userState);
            }

    关于服务端具体实现,服务部署配置等需要另写博客,待续。。

  • 相关阅读:
    flutter item列表左右滑动带出按钮选项
    flutter之Dismissible组件
    mac下最好用的抓包工具--charles简单操作教程
    flutter 开起charles抓包代理
    nodejs querystring模块
    node.js 中使用 Mongodb
    MongoDB 的高级查询 aggregate 聚合管道
    Mongodb 关系型数据库表(集合)与表(集合)之 间的几种关系
    Mongodb 的使用以及 Mongodb 账户权 限配置
    MongoDb 大数据查询优化、 MongoDB 索引、复合索引、唯一索引、 explain 分 析查询速度
  • 原文地址:https://www.cnblogs.com/log-long/p/3278140.html
Copyright © 2020-2023  润新知