次の方法で共有


RemotingServices.ExecuteMessage メソッド

指定したリモート オブジェクトに接続し、そのオブジェクトで提供された IMethodCallMessage を実行します。

Public Shared Function ExecuteMessage( _
   ByVal target As MarshalByRefObject, _   ByVal reqMsg As IMethodCallMessage _) As IMethodReturnMessage
[C#]
public static IMethodReturnMessage ExecuteMessage(MarshalByRefObjecttarget,IMethodCallMessagereqMsg);
[C++]
public: static IMethodReturnMessage* ExecuteMessage(MarshalByRefObject* target,IMethodCallMessage* reqMsg);
[JScript]
public static function ExecuteMessage(
   target : MarshalByRefObject,reqMsg : IMethodCallMessage) : IMethodReturnMessage;

パラメータ

  • target
    メソッドを呼び出す対象のリモート オブジェクト。
  • reqMsg
    指定したリモート オブジェクトのメソッドへのメソッド呼び出しメッセージ。

戻り値

リモート メソッドの応答。

例外

例外の種類 条件
SecurityException 直前の呼び出し元に、インフラストラクチャ アクセス許可がありません。

解説

現在のメソッドは、特別な場合にサーバーによって使用され、指定したメソッドの呼び出しを別のオブジェクト (リモート オブジェクトの場合もある) に転送します。このメソッドは、呼び出し元が適切なコンテキスト内にある場合にだけ呼び出すことができます。

使用例

[Visual Basic, C#, C++] ExecuteMessage メソッドを使用して、リモート オブジェクトにメソッド呼び出しを転送する方法の例を次に示します。

 
Public Sub ProcessMessageStart(requestMessage As IMessage, bClientSide As Boolean, bAsyncCall As Boolean) Implements IDynamicMessageSink.ProcessMessageStart

   Console.WriteLine(ControlChars.Cr + "ProcessMessageStart")
   Console.WriteLine("requestMessage = {0}", requestMessage)
   
   Try
      Console.WriteLine("SessionId = {0}.", RemotingServices.GetSessionIdForMethodMessage(CType(requestMessage, IMethodMessage)))
   Catch e As InvalidCastException
      Console.WriteLine("The requestMessage is not an IMethodMessage.")
   End Try
   
   Dim requestMethodCallMessage As IMethodCallMessage
   
   Try
      requestMethodCallMessage = CType(requestMessage, MethodCall)
      
      ' Prints the details of the IMethodCallMessage to the console
      Console.WriteLine(ControlChars.Cr + "MethodCall details")
      Console.WriteLine("Uri = {0}", requestMethodCallMessage.Uri)
      Console.WriteLine("TypeName = {0}", requestMethodCallMessage.TypeName)
      Console.WriteLine("MethodName = {0}", requestMethodCallMessage.MethodName)
      Console.WriteLine("ArgCount = {0}", requestMethodCallMessage.ArgCount)
      Console.WriteLine("MethodCall.Args")
      
      Dim o As Object
      For Each o In  requestMethodCallMessage.Args
         Console.WriteLine(ControlChars.Tab + "{0}", o)
      Next o 
      
      ' Sends this method call message to another server to replicate
      ' the call at the second server
      If requestMethodCallMessage.Uri = replicatedServiceUri Then
         
         Dim replicationService As SampleService = CType(Activator.GetObject(GetType(SampleService), replicationServerUrl + replicatedServiceUri), SampleService)
         Dim returnMessage As IMethodReturnMessage = RemotingServices.ExecuteMessage(replicationService, requestMethodCallMessage)
         
         ' Prints the results of the method call stored in the IMethodReturnMessage.
         Console.WriteLine(ControlChars.Cr + "Message returned by ExecuteMessage.")
         Console.WriteLine(ControlChars.Tab + "Exception = {0}", returnMessage.Exception)
         Console.WriteLine(ControlChars.Tab + "ReturnValue = {0}", returnMessage.ReturnValue)
         Console.WriteLine(ControlChars.Tab + "OutArgCount = {0}", returnMessage.OutArgCount)
         Console.WriteLine("Return message OutArgs")
         For Each o In  requestMethodCallMessage.Args
            Console.WriteLine(ControlChars.Tab + "{0}", o)
         Next o
         
      End If
      
   Catch e As InvalidCastException
      Console.WriteLine("The requestMessage is not a MethodCall")
   End Try

End Sub 'ProcessMessageStart

[C#] 
public void ProcessMessageStart(IMessage requestMessage, bool bClientSide, bool bAsyncCall) {
   
   Console.WriteLine("\nProcessMessageStart");
   Console.WriteLine("requestMessage = {0}", requestMessage);
   
   try {
      Console.WriteLine("SessionId = {0}.",
          RemotingServices.GetSessionIdForMethodMessage((IMethodMessage)requestMessage));
   }
   catch (InvalidCastException) {
      Console.WriteLine("The requestMessage is not an IMethodMessage.");
   }

   IMethodCallMessage requestMethodCallMessage;
   
   try {
      requestMethodCallMessage = (IMethodCallMessage)requestMessage;
      // Prints the details of the IMethodCallMessage to the console.
      Console.WriteLine("\nMethodCall details");
      Console.WriteLine("Uri = {0}", requestMethodCallMessage.Uri);
      Console.WriteLine("TypeName = {0}", requestMethodCallMessage.TypeName);
      Console.WriteLine("MethodName = {0}", requestMethodCallMessage.MethodName);
      Console.WriteLine("ArgCount = {0}", requestMethodCallMessage.ArgCount);
      
      Console.WriteLine("MethodCall.Args");
      foreach(object o in requestMethodCallMessage.Args)
          Console.WriteLine("\t{0}", o);
      
      // Sends this method call message to another server to replicate
      // the call at the second server.
      if (requestMethodCallMessage.Uri == replicatedServiceUri) {
         
         SampleService replicationService = 
            (SampleService)Activator.GetObject(typeof(SampleService), 
            replicationServerUrl + replicatedServiceUri);
         
         IMethodReturnMessage returnMessage = 
            RemotingServices.ExecuteMessage(replicationService, requestMethodCallMessage);
         
         // Prints the results of the method call stored in the IMethodReturnMessage.
         Console.WriteLine("\nMessage returned by ExecuteMessage.");
         Console.WriteLine("\tException = {0}", returnMessage.Exception);
         Console.WriteLine("\tReturnValue = {0}", returnMessage.ReturnValue);
         Console.WriteLine("\tOutArgCount = {0}", returnMessage.OutArgCount);
         Console.WriteLine("Return message OutArgs");
         
         foreach(object o in requestMethodCallMessage.Args)
            Console.WriteLine("\t{0}", o);
      }
   }
   catch (InvalidCastException) {
       Console.WriteLine("The requestMessage is not a MethodCall");
   }
}

[C++] 
public:
    void ProcessMessageStart(IMessage* requestMessage, bool /*bClientSide*/, bool /*bAsyncCall*/) 
    {
        Console::WriteLine(S"\nProcessMessageStart");
        Console::WriteLine(S"requestMessage = {0}", requestMessage);

        try 
        {
            Console::WriteLine(S"SessionId = {0}.",
                RemotingServices::GetSessionIdForMethodMessage(dynamic_cast<IMethodMessage*>(requestMessage)));
        }
        catch (InvalidCastException*) 
        {
            Console::WriteLine(S"The requestMessage is not an IMethodMessage*.");
        }

        IMethodCallMessage* requestMethodCallMessage;

        try 
        {
            requestMethodCallMessage = dynamic_cast<IMethodCallMessage*>(requestMessage);
            // Prints the details of the IMethodCallMessage* to the console.
            Console::WriteLine(S"\nMethodCall details");
            Console::WriteLine(S"Uri = {0}", requestMethodCallMessage->Uri);
            Console::WriteLine(S"TypeName = {0}", requestMethodCallMessage->TypeName);
            Console::WriteLine(S"MethodName = {0}", requestMethodCallMessage->MethodName);
            Console::WriteLine(S"ArgCount = {0}", __box(requestMethodCallMessage->ArgCount));

            Console::WriteLine(S"MethodCall::Args");
            IEnumerator* myEnum = requestMethodCallMessage->Args->GetEnumerator();
            while (myEnum->MoveNext()) 
            {
                Object* o = __try_cast<Object*>(myEnum->Current);

                Console::WriteLine(S"\t {0}", o);

                // Sends this method call message to another server to replicate
                // the call at the second server.
                if (requestMethodCallMessage->Uri == replicatedServiceUri) 
                {
                    String* repSvr = String::Format("{0}{1}", 
                        const_cast<String*>(replicationServerUrl), 
                        const_cast<String*>(replicatedServiceUri));
                    SampleService* replicationService = 
                        dynamic_cast<SampleService*>(Activator::GetObject(__typeof(SampleService), 
                        repSvr));

                    IMethodReturnMessage* returnMessage = 
                        RemotingServices::ExecuteMessage(replicationService, requestMethodCallMessage);

                    // Prints the results of the method call stored in the IMethodReturnMessage*.
                    Console::WriteLine(S"\nMessage returned by ExecuteMessage.");
                    Console::WriteLine(S"\tException = {0}", returnMessage->Exception);
                    Console::WriteLine(S"\tReturnValue = {0}", returnMessage->ReturnValue);
                    Console::WriteLine(S"\tOutArgCount = {0}", __box(returnMessage->OutArgCount));
                    Console::WriteLine(S"Return message OutArgs");

                    IEnumerator* myEnum = requestMethodCallMessage->Args->GetEnumerator();
                    while (myEnum->MoveNext()) 
                    {
                        Object* o = __try_cast<Object*>(myEnum->Current);

                        Console::WriteLine(S"\t {0}", o);
                    }
                }
            }
        }
        catch (InvalidCastException*) 
        {
            Console::WriteLine(S"The requestMessage is not a MethodCall");
        }
    }

[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 ファミリ

.NET Framework セキュリティ:

参照

RemotingServices クラス | RemotingServices メンバ | System.Runtime.Remoting 名前空間