zoukankan      html  css  js  c++  java
  • WebService异步调用

    发表时间:2007-7-3 14:41:00

    WebService方法代码:
    [WebMethod]
    public string HelloWorld() {
        System.Threading.Thread.Sleep(3000);
        return "Hello World";
    }

    调用wsdl ****.asmx /o:d:"ServiceA.cs
    生成WebService代理类,并加入工程

    调用页代码:
    public partial class _Default : System.Web.UI.Page
    {
        global::_ServiceA serviceA = new _ServiceA();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e) {
            this.TextBox1.Text = "";
           
            AsyncCallback asyncCallback = new AsyncCallback(CallBackExec);

            IAsyncResult asyncResult = serviceA.BeginHelloWorld(asyncCallback, null);
            asyncResult.AsyncWaitHandle.WaitOne();

            /*
            也可不用回调函数asyncCallBack
            string result = "";
            if (asyncResult.IsCompleted) {
                result = serviceA.EndHelloWorld(asyncResult);
            }
            this.TextBox1.Text = result;*/
        }

        private void CallBackExec(IAsyncResult asyncResult) {

            Response.Write("CallBackExec() called!");
            Response.Write(asyncResult.IsCompleted);

            this.TextBox1.Text = serviceA.EndHelloWorld(asyncResult);
        }
    }

  • 相关阅读:
    如何面试你的面试官
    给老婆的一篇文章
    机器学习:选对时机直线超车
    面试技巧:带走面试官的节奏
    微信红包的随机算法是怎样实现的?
    全栈技术导图
    AI时代:推荐引擎正在塑造人类
    冲顶大会APP技术选型及架构设计
    多域名解析及延伸知识点
    在编程中为所欲为[圣诞版]
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1446273.html
Copyright © 2011-2022 走看看