HttpSimpleClientProtocol.EndInvoke(IAsyncResult) Method

Definition

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

C#
protected object EndInvoke(IAsyncResult asyncResult);

Parameters

Returns

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

Exceptions

asyncResult is not the return value from the BeginInvoke(String, String, Object[], AsyncCallback, Object) method.

Examples

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.

ASP.NET (C#)

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.

C#
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.

ASP.NET (C#)
<%@ 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;
          }
 }

Applies to

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1