发表时间: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);
    }
}

相关文章:

  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2021-08-16
猜你喜欢
  • 2022-01-25
  • 2021-12-02
  • 2022-02-19
  • 2021-08-09
  • 2022-02-16
相关资源
相似解决方案