HttpSimpleClientProtocol.BeginInvoke メソッド

定義

XML Web サービスのメソッドの非同期呼び出しを開始します。

protected:
 IAsyncResult ^ BeginInvoke(System::String ^ methodName, System::String ^ requestUrl, cli::array <System::Object ^> ^ parameters, AsyncCallback ^ callback, System::Object ^ asyncState);
protected IAsyncResult BeginInvoke (string methodName, string requestUrl, object[] parameters, AsyncCallback callback, object asyncState);
member this.BeginInvoke : string * string * obj[] * AsyncCallback * obj -> IAsyncResult
Protected Function BeginInvoke (methodName As String, requestUrl As String, parameters As Object(), callback As AsyncCallback, asyncState As Object) As IAsyncResult

パラメーター

methodName
String

XML Web サービス メソッドの名前。

requestUrl
String

WebRequest を作成するときに使用する URL。

parameters
Object[]

XML Web サービス メソッドに渡すパラメーターを格納しているオブジェクトの配列。 配列内の値の順序は、呼び出し元の派生クラス メソッドに渡されたパラメーターの順序に対応しています。

callback
AsyncCallback

非同期メソッドの呼び出しが完了したときに呼び出されるデリゲート。 callbacknull の場合、このデリゲートは呼び出されません。

asyncState
Object

クライアントから提供された追加情報。

戻り値

XML Web サービス メソッドからの戻り値を取得するために、IAsyncResult メソッドに渡すことのできる EndInvoke(IAsyncResult)

例外

要求はサーバー コンピューターに到達しましたが、正常に処理されませんでした。

次のコード例は、 という名前 Mathの XML Web サービスを呼び出す ASP.NET Web フォームです。 関数内で EnterBtn_Click 、Web フォームは XML Web サービス メソッドの非同期呼び出しを開始して Add 完了します。

<%@ Page Language="VB" %>
<html>
    <script language="VB" runat="server">
    Sub EnterBtn_Click(Src As Object, E As EventArgs)
        Dim math As New MyMath.Math()
        
        ' Call to Add XML Web service method asynchronously.
        Dim result As IAsyncResult = math.BeginAdd(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text), Nothing, Nothing)
        
        ' Wait for the asynchronous call to complete.
        result.AsyncWaitHandle.WaitOne()
        
        ' Complete the asynchronous call to the Add XML Web service method.
        Dim iTotal As Integer = math.EndAdd(result)
        
        Total.Text = "Total: " & iTotal.ToString()
    End Sub 'EnterBtn_Click
 
  </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>

次のコード例は、以下の XML Web サービスの Web サービス記述言語ツール (Wsdl.exe) Math によって生成されるプロキシ クラスです。 プロキシ クラスの BeginAdd メソッド内で、 メソッドは BeginInvoke XML Web サービス メソッドの非同期呼び出しを Add 開始します。

namespace MyMath
{
   [XmlRootAttribute("snippet1>",Namespace="http://MyMath/",IsNullable=false)]
   public ref class Math: public HttpGetClientProtocol
   {
   public:
      Math()
      {
         this->Url = "http://www.contoso.com/math.asmx";
      }

      [HttpMethodAttribute(System::Web::Services::Protocols::XmlReturnReader::typeid,
      System::Web::Services::Protocols::UrlParameterWriter::typeid)]
      int Add( String^ num1, String^ num2 )
      {
         array<Object^>^temp0 = {num1,num2};
         return  *dynamic_cast<int^>(this->Invoke( "Add", String::Concat( this->Url, "/Add" ), temp0 ));
      }

      IAsyncResult^ BeginAdd( String^ num1, String^ num2, AsyncCallback^ callback, Object^ asyncState )
      {
         array<Object^>^temp1 = {num1,num2};
         return this->BeginInvoke( "Add", String::Concat( this->Url, "/Add" ), temp1, callback, asyncState );
      }

      int EndAdd( IAsyncResult^ asyncResult )
      {
         return  *dynamic_cast<int^>(this->EndInvoke( asyncResult ));
      }
   };
}
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)));
        }
    }
}
Namespace MyMath
    <XmlRootAttribute("int", Namespace := "http://MyMath/", IsNullable := False)> _
    Public Class Math
        Inherits HttpGetClientProtocol
        
        Public Sub New()
            Me.Url = "http://www.contoso.com/math.asmx"
        End Sub
        
        <HttpMethodAttribute(GetType(XmlReturnReader), GetType(UrlParameterWriter))> _
        Public Function Add(num1 As String, num2 As String) As Integer
            Return CInt(Me.Invoke("Add", Me.Url + "/Add", New Object() {num1, num2}))
        End Function 'Add
        
        
        Public Function BeginAdd(num1 As String, num2 As String, callback As AsyncCallback, asyncState As Object) As IAsyncResult
            Return Me.BeginInvoke("Add", Me.Url + "/Add", New Object() {num1, num2}, callback, asyncState)
        End Function 'BeginAdd
        
        
        Public Function EndAdd(asyncResult As IAsyncResult) As Integer
            Return CInt(Me.EndInvoke(asyncResult))
        End Function 'EndAdd
    End Class
End Namespace 'MyMath

次のコード例は、前の Math プロキシ クラスが作成された XML Web サービスです。

<%@ 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;
          }
 }
<%@ WebService Language="VB" Class="Math"%>
Imports System.Web.Services
Imports System

Public Class Math
    <WebMethod()> _
    Public Function Add(num1 As Integer, num2 As Integer) As Integer
        Return num1 + num2
    End Function 'Add
End Class 'Math

注釈

パラメーターは methodName 、パラメーターの型を検索し、メソッドを呼び出しているメソッドの値を返すために使用されます BeginInvoke 。 また、 メソッドに追加された可能性のあるカスタム属性を検索するためにも使用されます。 SoapDocumentMethodAttributeSoapRpcMethodAttribute、および は、 XmlElementAttribute HTTP プロトコルに必要な派生メソッドに関する追加情報を提供します。

asyncStateは にcallback渡され、 メソッドから返される にBeginInvoke含まれますIAsyncResult。 非同期呼び出しのコンテキストから の非同期結果の処理に情報を渡す場合に callback便利です。

適用対象

こちらもご覧ください