次の方法で共有


LogicalMethodInfo.BeginInvoke メソッド

この LogicalMethodInfo で表されるメソッドの非同期呼び出しを開始します。

Public Function BeginInvoke( _
   ByVal target As Object, _   ByVal values() As Object, _   ByVal callback As AsyncCallback, _   ByVal asyncState As Object _) As IAsyncResult
[C#]
public IAsyncResult BeginInvoke(objecttarget,object[] values,AsyncCallbackcallback,objectasyncState);
[C++]
public: IAsyncResult* BeginInvoke(Object* target,Object* values __gc[],AsyncCallback* callback,Object* asyncState);
[JScript]
public function BeginInvoke(
   target : Object,values : Object[],callback : AsyncCallback,asyncState : Object) : IAsyncResult;

パラメータ

  • target
    メソッドの呼び出し元となる Object のインスタンス。
  • values
    呼び出すメソッドの引数リスト。これは、メソッドのパラメータと同じ数、順序、型のオブジェクトの配列です。メソッドにパラメータが必要ない場合、 values は null 参照 (Visual Basic では Nothing) です。
  • callback
    非同期呼び出しが完了したときに呼び出されるデリゲート。 callback が null 参照 (Visual Basic では Nothing) の場合、このデリゲートは呼び出されません。
  • asyncState
    デリゲートに渡されるステータス情報。

戻り値

リモート メソッドの呼び出しからの戻り値を取得するために、 EndInvoke に渡される IAsyncResult

例外

例外の種類 条件
TargetException target パラメータが null 参照 (Visual Basic では Nothing) です。
ArgumentException values の数、型、およびパラメータの順序が、呼び出されたメソッドのシグネチャと一致しません。
MemberAccessException 呼び出し元に、このメソッドを呼び出すためのアクセス許可がありません。

使用例

 
Public Shared Sub Main()

   ' Get the type information.
   ' Note: The MyMath class is a proxy class generated by the Wsdl.exe 
   ' utility for the Math Web Service. This class can also be found in
   ' the SoapHttpClientProtocol class example. 
   Dim myType As Type = GetType(MyMath.MyMath)

   ' Get the method info.
   Dim myBeginMethod As MethodInfo = myType.GetMethod("BeginAdd")
   Dim myEndMethod As MethodInfo = myType.GetMethod("EndAdd")

   ' Create an instance of the LogicalMethodInfo class.
   Dim myLogicalMethodInfo As LogicalMethodInfo = _
      LogicalMethodInfo.Create(New MethodInfo() {myBeginMethod, myEndMethod}, _
      LogicalMethodTypes.Async)(0)

   ' Get an instance of the proxy class.
   Dim myMathService As New MyMath.MyMath()

   ' Call the MyEndIntimationMethod method to intimate the end of 
   ' the asynchronous call.
   Dim myAsyncCallback As New AsyncCallback(AddressOf MyEndIntimationMethod)

   ' Beging to invoke the Add method.
   Dim myAsyncResult As IAsyncResult = _
      myLogicalMethodInfo.BeginInvoke( _
      myMathService, New Object() {10, 10}, myAsyncCallback, Nothing)

   ' Wait until invoke is complete.
   myAsyncResult.AsyncWaitHandle.WaitOne()

   ' Get the result.
   Dim myReturnValue() As Object
   myReturnValue = myLogicalMethodInfo.EndInvoke(myMathService, myAsyncResult)

   Console.WriteLine(("Sum of 10 and 10 is " & myReturnValue(0)))
End Sub

' This method will be called at the end of asynchronous call.
Shared Sub MyEndIntimationMethod(ByVal Result As IAsyncResult)
   Console.WriteLine("Asynchronous call on method 'Add' finished.")
End Sub


[C#] 
public static void Main()
{
   // Get the type information.
   // Note: The MyMath class is a proxy class generated by the Wsdl.exe
   // utility for the Math Web service. This class can also be found in 
   // the SoapHttpClientProtocol class example. 
   Type myType = typeof(MyMath.MyMath);

   // Get the method info.
   MethodInfo myBeginMethod = myType.GetMethod("BeginAdd");
   MethodInfo myEndMethod = myType.GetMethod("EndAdd");

   // Create an instance of the LogicalMethodInfo class.
   LogicalMethodInfo myLogicalMethodInfo = 
      (LogicalMethodInfo.Create(new MethodInfo[] {myBeginMethod,myEndMethod},
      LogicalMethodTypes.Async))[0];

   // Get an instance of the proxy class.
   MyMath.MyMath myMathService = new MyMath.MyMath();

   // Call the MyEndIntimationMethod method to intimate the end of 
   // the asynchronous call.
   AsyncCallback myAsyncCallback = new AsyncCallback(MyEndIntimationMethod);

   // Begin to invoke the Add method.
   IAsyncResult myAsyncResult = myLogicalMethodInfo.BeginInvoke(
      myMathService,new object[]{10,10},myAsyncCallback,null);
   
   // Wait until invoke is complete.
   myAsyncResult.AsyncWaitHandle.WaitOne();
   
   // Get the result.
   object[] myReturnValue;
   myReturnValue = myLogicalMethodInfo.EndInvoke(myMathService,myAsyncResult);
   
   Console.WriteLine("Sum of 10 and 10 is " + myReturnValue[0]);
}

// This method will be called at the end of the asynchronous call.
static void MyEndIntimationMethod(IAsyncResult Result)
{
   Console.WriteLine("Asynchronous call on Add method finished.");
}

[C++] 
public:
   static void main()
   {
      // Get the type information.
      // Note: The MyMath class is a proxy class generated by the Wsdl.exe
      // utility for the Math Web service. This class can also be found in
      // the SoapHttpClientProtocol class example.
      Type* myType = __typeof(MyMath::MyMath);

      // Get the method info.
      MethodInfo* myBeginMethod = myType->GetMethod(S"BeginAdd");
      MethodInfo* myEndMethod = myType->GetMethod(S"EndAdd");

      // Create an instance of the LogicalMethodInfo class.
      MethodInfo* temp0 [] = {myBeginMethod,myEndMethod};
      LogicalMethodInfo* myLogicalMethodInfo =
         (LogicalMethodInfo::Create(temp0,
         LogicalMethodTypes::Async))[0];

      // Get an instance of the proxy class.
      MyMath::MyMath* myMathService = new MyMath::MyMath();

      // Call the MyEndIntimationMethod method to intimate the end of
      // the asynchronous call.
      AsyncCallback* myAsyncCallback = new AsyncCallback(0, MyEndIntimationMethod);

      // Begin to invoke the Add method.
      Object* temp1 [] = {__box(10),__box(10)};
      IAsyncResult* myAsyncResult = myLogicalMethodInfo->BeginInvoke(
         myMathService,temp1,myAsyncCallback,0);

      // Wait until invoke is complete.
      myAsyncResult->AsyncWaitHandle->WaitOne();

      // Get the result.
      Object* myReturnValue[];
      myReturnValue = myLogicalMethodInfo->EndInvoke(myMathService,myAsyncResult);

      Console::WriteLine(S"Sum of 10 and 10 is {0}", myReturnValue[0]);
   }

   // This method will be called at the end of the asynchronous call.
   static void MyEndIntimationMethod(IAsyncResult* /*Result*/)
   {
      Console::WriteLine(S"Asynchronous call on Add method finished.");
   }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

LogicalMethodInfo クラス | LogicalMethodInfo メンバ | System.Web.Services.Protocols 名前空間