zoukankan      html  css  js  c++  java
  • 异步调用开发应用总结(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);
            }

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

  • 相关阅读:
    Mysql 中的日期时间字符串查询
    PyQt5中的信号与槽,js 与 Qt 对象之间互相调用
    vue学习初探
    【Java】JDBCUtil模板
    【明哥报错簿】之【 "javax.servlet.http.HttpServlet" was not found on the Java Build Path || HttpServletRequest/HttpServletResponse cannot be resolved to a type】
    【开发工具IDE】Eclipse相关配置
    【Java】JAVA开发人员常见环境工具安装
    【Java】自动获取某表某列的最大ID数
    【Java】全站编码过滤器GenericEncodingFilter代码与配置
    【Linux】无法将 Ethernet0 连接到虚拟网络“VMnet8”
  • 原文地址:https://www.cnblogs.com/log-long/p/3278140.html
Copyright © 2011-2022 走看看