Freigeben über


RemotingServices.ExecuteMessage-Methode

Stellt eine Verbindung mit dem angegebenen Remoteobjekt her und führt die bereitgestellte IMethodCallMessage für dieses aus.

Namespace: System.Runtime.Remoting
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function ExecuteMessage ( _
    target As MarshalByRefObject, _
    reqMsg As IMethodCallMessage _
) As IMethodReturnMessage
'Usage
Dim target As MarshalByRefObject
Dim reqMsg As IMethodCallMessage
Dim returnValue As IMethodReturnMessage

returnValue = RemotingServices.ExecuteMessage(target, reqMsg)
public static IMethodReturnMessage ExecuteMessage (
    MarshalByRefObject target,
    IMethodCallMessage reqMsg
)
public:
static IMethodReturnMessage^ ExecuteMessage (
    MarshalByRefObject^ target, 
    IMethodCallMessage^ reqMsg
)
public static IMethodReturnMessage ExecuteMessage (
    MarshalByRefObject target, 
    IMethodCallMessage reqMsg
)
public static function ExecuteMessage (
    target : MarshalByRefObject, 
    reqMsg : IMethodCallMessage
) : IMethodReturnMessage

Parameter

  • target
    Das Remoteobjekt, dessen Methode Sie aufrufen möchten.
  • reqMsg
    Die Meldung für einen Methodenaufruf an die Methode des angegebenen Remoteobjekts.

Rückgabewert

Die Antwort der Remotemethode.

Ausnahmen

Ausnahmetyp Bedingung

SecurityException

Der direkte Aufrufer verfügt nicht über die Berechtigung für die Infrastruktur.

RemotingException

Die Methode wurde nicht aus dem systemeigenen Kontext des Objekts aufgerufen.

Hinweise

Die aktuelle Methode wird in besonderen Fällen vom Server verwendet, um den angegebenen Methodenaufruf an ein weiteres Objekt, möglicherweise ein Remoteobjekt, weiterzuleiten. Diese Methode kann nur aufgerufen werden, wenn sich der Aufrufer im entsprechenden Kontext befindet.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mit der ExecuteMessage-Methode Methodenaufrufe an Remoteobjekte weitergeleitet werden.

<SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
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
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
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");
   }
}
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::LinkDemand, 
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
virtual void ProcessMessageStart( IMessage^ requestMessage, bool /*bClientSide*/, bool /*bAsyncCall*/ )
{
   Console::WriteLine( "\nProcessMessageStart" );
   Console::WriteLine( "requestMessage = {0}", requestMessage );
   try
   {
      Console::WriteLine( "SessionId = {0}.", RemotingServices::GetSessionIdForMethodMessage( dynamic_cast<IMethodMessage^>(requestMessage) ) );
   }
   catch ( InvalidCastException^ ) 
   {
      Console::WriteLine( "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( "\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" );
      IEnumerator^ myEnum = requestMethodCallMessage->Args->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Object^ o = safe_cast<Object^>(myEnum->Current);
         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 )
         {
            String^ repSvr = String::Format(  "{0}{1}", const_cast<String^>(replicationServerUrl), const_cast<String^>(replicatedServiceUri) );
            SampleService^ replicationService = dynamic_cast<SampleService^>(Activator::GetObject( SampleService::typeid, repSvr ));
            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" );
            IEnumerator^ myEnum = requestMethodCallMessage->Args->GetEnumerator();
            while ( myEnum->MoveNext() )
            {
               Object^ o = safe_cast<Object^>(myEnum->Current);
               Console::WriteLine( "\t {0}", o );
            }
         }
      }
   }
   catch ( InvalidCastException^ ) 
   {
      Console::WriteLine( "The requestMessage is not a MethodCall" );
   }
}
public void ProcessMessageStart(IMessage requestMessage,boolean bClientSide,
    boolean bAsyncCall)
{
    Console.WriteLine("\nProcessMessageStart");
    Console.WriteLine("requestMessage = {0}", requestMessage);
    try {
        Console.WriteLine("SessionId = {0}.", RemotingServices.
            GetSessionIdForMethodMessage((IMethodMessage)requestMessage));
    }
    catch (InvalidCastException exp) {
        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.get_Uri());
        Console.WriteLine("TypeName = {0}", requestMethodCallMessage.
            get_TypeName());
        Console.WriteLine("MethodName = {0}", requestMethodCallMessage.
            get_MethodName());
        Console.WriteLine("ArgCount = {0}",
            (System.Int32)requestMethodCallMessage.get_ArgCount());
        Console.WriteLine("MethodCall.Args");            
        Object o = null;
        for (int iCtr = 0; iCtr < requestMethodCallMessage.get_Args().
            get_Length(); iCtr++) {
            o = requestMethodCallMessage.get_Args()[iCtr];
            Console.WriteLine("\t{0}", o);
        }
        // Sends this method call message to another server to replicate
        // the call at the second server.
        if (requestMethodCallMessage.get_Uri().Equals(replicatedServiceUri)) {
            SampleService replicationService = (SampleService)(Activator.
                GetObject(SampleService.class.ToType(), 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.
                get_Exception());
            Console.WriteLine("\tReturnValue = {0}", returnMessage.
                get_ReturnValue());
            Console.WriteLine("\tOutArgCount = {0}", 
                (System.Int32)returnMessage.get_OutArgCount());
            Console.WriteLine("Return message OutArgs");                                
            for (int iCtr1 = 0; iCtr1 < requestMethodCallMessage.get_Args().
                get_Length(); iCtr1++) {
                o = requestMethodCallMessage.get_Args()[iCtr1];
                Console.WriteLine("\t{0}", o);
            }
        }
    }
    catch (InvalidCastException exp) {
        Console.WriteLine("The requestMessage is not a MethodCall");
    }
} //ProcessMessageStart

.NET Framework-Sicherheit

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

RemotingServices-Klasse
RemotingServices-Member
System.Runtime.Remoting-Namespace