HttpSimpleClientProtocol.EndInvoke(IAsyncResult) 方法

定義

使用 HTTP 完成 XML Web Service 方法的非同步引動過程。

C#
protected object EndInvoke (IAsyncResult asyncResult);

參數

傳回

Object

物件的陣列,包含 XML Web Service 方法的傳回值以及任何傳址 (By Reference) 方式或 out 的參數。

例外狀況

範例

下列程式碼範例是 ASP.NET Web Form,它會呼叫名為 的 Math XML Web 服務。 EnterBtn_Click在 函式中,Web Form 會啟動並完成 XML Web 服務方法的 Add 非同步調用。

ASP.NET (C#)

下列程式碼範例是由下列 XML Web 服務的 Web 服務描述語言工具 (Wsdl.exe) Math 所產生的 Proxy 類別。 在 EndAdd Proxy 類別的 方法內, EndInvoke 方法會啟動 XML Web 服務方法的 Add 非同步調用。

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)));
        }
    }
}

下列程式碼範例是 Math 建立上述 Proxy 類別的 XML Web 服務。

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;
          }
 }

適用於

產品 版本
.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