About asynchronous invocation instances of WebService

Source: Internet
Author: User
web| Asynchronous

A simple instance of asynchronous invocation about WebService
In any case, the caller's code is the same whether it is invoked asynchronously or synchronously, and the code of the callee is the same.

Now, let's take an example of an asynchronous call to a webservice.
This is a WebService

_
Public Function delcurtable (ByVal tbname as String) as Boolean
Try
Return True
Catch ex as Exception
Return False
End Try
End Function

I'm not going to explain this webservice method of synchronous invocation.
Asynchronous invocation:
Private A as Vbwebservice. Datamanage ' defines a WebService variable
Dim ar as IAsyncResult
Public Sub Callback1 (ByVal ar As IAsyncResult)
"No code can be written here.
' Here the code starts running after the caller has run
End Sub

#region "Call asynchronously"
Private Sub btnStart_Click ()
Dim cb As Asyncallback=new Asyncallback (address (ME.CALLBACK1))
Ar=a.begindelcurtable ("ZDF", Cb,a)
End Sub


Private Sub Btnend_click ()
If AR is Nothing Then
Exit Sub
End If
If Ar. IsCompleted Then
Dim m as Boolean=a.enddelcurtable (AR)
MessageBox.Show (m.tostring)
End If
End Sub
#end Region
Note: "Returns the result of an asynchronous call that can only be invoked once, and if you want to do it again, you must rerun the Begin method."
The above is the usage of vb.net, the following is the use of C #
Cwebservice.datamanage A;
System.IAsyncResult ar;
private void Form1_Load (object sender, System.EventArgs e)
{
A=new Cwebservice.datamanage ();
}


public void CallBack1 (System.IAsyncResult ar)
{
}

private void btnStart_Click (object sender, System.EventArgs e)
{
System.AsyncCallback cb=new AsyncCallback (this. CALLBACK1);
Ar=a.begindelcurtable ("Zhang", cb,a);
}

private void Btnend_click (object sender, System.EventArgs e)
{
if (ar==null)
{
MessageBox.Show ("null");
return;
}
if (AR. iscompleted)
{
BOOL M=a.enddelcurtable (AR);
MessageBox.Show (M.tostring ());
}
Else
{
MessageBox.Show ("for completion");
}
}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.