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

  • 相关阅读:
    PacificA协议小结
    raft协议小结
    python爬虫抓取图片
    composer 的使用和常用命令大全
    php批量同步数据
    VMware虚拟机的安装与配置
    国家和地区代码表
    js判断h5页面地址的打开方式(微信、pc、移动端)
    phpexcel图片获取
    python的文件操作及简单的用例
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1446273.html
Copyright © 2011-2022 走看看