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);
        }
    }

  • 相关阅读:
    递归和迭代
    The Rose
    读周国平作品有感
    matlab最小二乘法数据拟合函数详解
    读周国平作品有感
    three.js之创建一条直线
    three.js之创建一个几何体
    Go语言标准库之strconv
    Go语言基础之网络编程
    Go语言基础之并发
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1446273.html
Copyright © 2011-2022 走看看