This documentation is archived and is not being maintained.

How to: Make an Asynchronous Call from a Web Service Client

Visual Studio 2010

This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation .

The following code example demonstrates how to make an asynchronous call to a Web service from a client application. This example illustrates one of the guidelines explained in the topic, Design Guidelines for XML Web Services Created Using ASP.NET.,VS.100).gif Security Note:
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.


<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>
   <script language="VB" runat="server">
      Sub EnterBtn_Click(Src As Object, E As EventArgs) 
         Dim math As New MyMath.Math()
         ' Call to Add Web service method asynchronously 
         ' and then wait for it to complete.
         Dim result As IAsyncResult = _
                         math.BeginAdd(Convert.ToInt32(Num1.Text), _
                                       Convert.ToInt32(Num2.Text), _
                                       Nothing, _
         ' Wait for asynchronous call to complete.
         ' Complete the asynchronous call to Add Web service method.
         Dim addtotal As Single = math.EndAdd(result)
         ' Display results in a Label control.
         Total.Text = "Total: " & addtotal.ToString()
      End Sub
   <form action="MathClient.aspx" runat=server>
      <font face="Verdana"> 
         Enter the two numbers you want to add and then press 
         the Total button.
         Number 1: 
         <asp:textbox id="Num1" 
         Number 2: 
         <asp:textbox id="Num2" 
         <asp:button id="Total_Button"
         <asp:label id="Total" runat=server/>

See Also