Export (0) Print
Expand All

HttpSimpleClientProtocol.EndInvoke Method

Completes asynchronous invocation of an XML Web service method using HTTP.

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

protected Object EndInvoke(
	IAsyncResult asyncResult
)

Parameters

asyncResult
Type: System.IAsyncResult

The IAsyncResult returned from the BeginInvoke method.

Return Value

Type: System.Object
An array of objects containing the return value and any by reference or out parameters for the XML Web service method.

ExceptionCondition
ArgumentException

asyncResult is not the return value from the BeginInvoke method.

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 EndAdd method of the proxy class, the EndInvoke 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 above 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;
          }
 }

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft