RemotingServices::ExecuteMessage Method
Connects to the specified remote object, and executes the provided IMethodCallMessage on it.
Assembly: mscorlib (in mscorlib.dll)
public: static IMethodReturnMessage^ ExecuteMessage( MarshalByRefObject^ target, IMethodCallMessage^ reqMsg )
Parameters
- target
- Type: System::MarshalByRefObject
The remote object whose method you want to call.
- reqMsg
- Type: System.Runtime.Remoting.Messaging::IMethodCallMessage
A method call message to the specified remote object's method.
Return Value
Type: System.Runtime.Remoting.Messaging::IMethodReturnMessageThe response of the remote method.
| Exception | Condition |
|---|---|
| SecurityException | The immediate caller does not have infrastructure permission. |
| RemotingException | The method was called from a context other than the native context of the object. |
The following code example demonstrates how to use the ExecuteMessage method to forward method calls to remote objects.
[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" ); } }
- SecurityPermission
for operating with infrastructure code. Demand value: SecurityAction::LinkDemand; Permission value: SecurityPermissionFlag::Infrastructure
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.