Export (0) Print
Expand All

HttpSimpleClientProtocol.BeginInvoke Method

Starts an asynchronous invocation of a method of an XML Web service.

Namespace: System.Web.Services.Protocols
Assembly: System.Web.Services (in system.web.services.dll)

protected IAsyncResult BeginInvoke (
	string methodName,
	string requestUrl,
	Object[] parameters,
	AsyncCallback callback,
	Object asyncState
)
protected IAsyncResult BeginInvoke (
	String methodName, 
	String requestUrl, 
	Object[] parameters, 
	AsyncCallback callback, 
	Object asyncState
)
protected function BeginInvoke (
	methodName : String, 
	requestUrl : String, 
	parameters : Object[], 
	callback : AsyncCallback, 
	asyncState : Object
) : IAsyncResult
Not applicable.

Parameters

methodName

The name of the XML Web service method.

requestUrl

The URL to use when creating the WebRequest.

parameters

An array of objects containing the parameters to pass to the XML Web service method. The order of the values in the array corresponds to the order of the parameters in the calling method of the derived class.

callback

The delegate to call when the asynchronous method call is complete. If callback is a null reference (Nothing in Visual Basic), the delegate is not called.

asyncState

The additional information supplied by a client.

Return Value

An IAsyncResult that can be passed to the EndInvoke method to obtain the return values from the XML Web service method.

Exception typeCondition

Exception

The request reached the server computer, but was not processed successfully.

The methodName parameter is used to find the types of the parameters and return values of the method that is invoking the BeginInvoke method. It is also used to find custom attributes that may have been added to the method. SoapDocumentMethodAttribute, SoapRpcMethodAttribute, and XmlElementAttribute provide additional information on the derived method that is required for the HTTP protocol.

asyncState is passed into callback and is included in the IAsyncResult that is returned from the BeginInvoke method. It is useful for passing information from the context of the asynchronous call to the handling of the asynchronous result in callback.

The following code example is an ASP.NET Web Form, which calls an XML Web service named Math. Within the EnterBtn_Click function, the Web Form starts and completes an asynchronous invocation of the Add XML Web service method.

<%@ Page Language="C#" %>
<html>
    <script language="C#" runat="server">
       void EnterBtn_Click(Object Src, EventArgs E) 
          {
             MyMath.Math math = new MyMath.Math();
 
         // Call the Add XML Web service method asynchronously.
         IAsyncResult result = math.BeginAdd(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text), null, null);
             
         // Wait for the asynchronous call to complete.
         result.AsyncWaitHandle.WaitOne();
 
         // Complete the asynchronous call to the Add XML Web service method.
         int total = math.EndAdd(result);
 
         Total.Text = "Total: " + total.ToString();
         }
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>

The following code example is a proxy class generated by the Web Services Description Language tool (Wsdl.exe) for the Math XML Web service below. Within the BeginAdd method of the proxy class, the BeginInvoke method starts an asynchronous invocation of the Add XML Web service method.

namespace MyMath {
    [XmlRootAttribute("int", Namespace="http://MyMath/", IsNullable=false)]
    public class Math : HttpGetClientProtocol {
       public Math() 
       {
          this.Url = "http://www.contoso.com/math.asmx";
       }
        
       [HttpMethodAttribute(typeof(System.Web.Services.Protocols.XmlReturnReader),
       typeof(System.Web.Services.Protocols.UrlParameterWriter))]
       public int Add(int num1, int num2) 
       {
          return ((int)(this.Invoke("Add", ((this.Url) + ("/Add")), new object[] {num1,
                         num2})));
       }
         
       public IAsyncResult BeginAdd(int num1, int num2, AsyncCallback callback, object asyncState) 
       {
          return this.BeginInvoke("Add", ((this.Url) + ("/Add")), new object[] {num1,
                         num2}, callback, asyncState);
       }
         
       public int EndAdd(IAsyncResult asyncResult) 
       {
          return ((int)(this.EndInvoke(asyncResult)));
       }
         
     }
 }

The following code example is the Math XML Web service, from which the preceding proxy class was created.

<%@ WebService Language="C#" Class="Math"%>
 using System.Web.Services;
 using System;
 
 public class Math {
      [ WebMethod ]
      public int Add(int num1, int num2) {
          return num1+num2;
          }
 }

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft