RemotingServices.ExecuteMessage 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
連接至指定的遠端物件,並且執行在它上面執行已提供的 IMethodCallMessage。
public:
static System::Runtime::Remoting::Messaging::IMethodReturnMessage ^ ExecuteMessage(MarshalByRefObject ^ target, System::Runtime::Remoting::Messaging::IMethodCallMessage ^ reqMsg);
public static System.Runtime.Remoting.Messaging.IMethodReturnMessage ExecuteMessage (MarshalByRefObject target, System.Runtime.Remoting.Messaging.IMethodCallMessage reqMsg);
[System.Security.SecurityCritical]
public static System.Runtime.Remoting.Messaging.IMethodReturnMessage ExecuteMessage (MarshalByRefObject target, System.Runtime.Remoting.Messaging.IMethodCallMessage reqMsg);
static member ExecuteMessage : MarshalByRefObject * System.Runtime.Remoting.Messaging.IMethodCallMessage -> System.Runtime.Remoting.Messaging.IMethodReturnMessage
[<System.Security.SecurityCritical>]
static member ExecuteMessage : MarshalByRefObject * System.Runtime.Remoting.Messaging.IMethodCallMessage -> System.Runtime.Remoting.Messaging.IMethodReturnMessage
Public Shared Function ExecuteMessage (target As MarshalByRefObject, reqMsg As IMethodCallMessage) As IMethodReturnMessage
參數
- target
- MarshalByRefObject
遠端物件,具有您要呼叫的方法。
- reqMsg
- IMethodCallMessage
指定遠端物件方法的方法呼叫訊息。
傳回
遠端方法的回應。
- 屬性
例外狀況
立即呼叫端沒有基礎結構使用權限。
此方法是從物件原生內容以外的內容呼叫。
範例
下列程式代碼範例示範如何使用 ExecuteMessage 方法將方法呼叫轉送至遠端物件。
[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, 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");
}
}
<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
備註
伺服器會在特殊情況下使用目前的 方法,將指定的方法呼叫轉送到另一個可能遠端的物件。 只有在呼叫端位於適當的內容時,才能呼叫這個方法。