RealProxy.Invoke(IMessage) 方法

定义

当在派生类中重写时,对当前实例所表示的远程对象调用在所提供的 IMessage 中指定的方法。

public:
 abstract System::Runtime::Remoting::Messaging::IMessage ^ Invoke(System::Runtime::Remoting::Messaging::IMessage ^ msg);
public abstract System.Runtime.Remoting.Messaging.IMessage Invoke (System.Runtime.Remoting.Messaging.IMessage msg);
abstract member Invoke : System.Runtime.Remoting.Messaging.IMessage -> System.Runtime.Remoting.Messaging.IMessage
Public MustOverride Function Invoke (msg As IMessage) As IMessage

参数

msg
IMessage

IMessage,包含有关方法调用的信息的 IDictionary

返回

调用的方法所返回的消息,包含返回值和所有 outref 参数。

示例

virtual IMessage^ Invoke( IMessage^ myMessage ) override
{
   Console::WriteLine( "MyProxy 'Invoke method' Called..." );
   if ( dynamic_cast<IMethodCallMessage^>(myMessage) )
   {
      Console::WriteLine( "IMethodCallMessage*" );
   }

   if ( dynamic_cast<IMethodReturnMessage^>(myMessage) )
   {
      Console::WriteLine( "IMethodReturnMessage*" );
   }

   if ( dynamic_cast<IConstructionCallMessage^>(myMessage) )
   {
      // Initialize a new instance of remote object
      IConstructionReturnMessage^ myIConstructionReturnMessage = this->InitializeServerObject( static_cast<IConstructionCallMessage^>(myMessage) );
      ConstructionResponse^ constructionResponse = gcnew ConstructionResponse( nullptr,static_cast<IMethodCallMessage^>(myMessage) );
      return constructionResponse;
   }

   IDictionary^ myIDictionary = myMessage->Properties;
   IMessage^ returnMessage;
   myIDictionary[ "__Uri" ] = myUri;

   // Synchronously dispatch messages to server.
   returnMessage = ChannelServices::SyncDispatchMessage( myMessage );

   // Pushing return value and OUT parameters back onto stack.
   IMethodReturnMessage^ myMethodReturnMessage = dynamic_cast<IMethodReturnMessage^>(returnMessage);
   return returnMessage;
}
public override IMessage Invoke(IMessage myMessage)
{
   Console.WriteLine("MyProxy 'Invoke method' Called...");
   if (myMessage is IMethodCallMessage)
   {
      Console.WriteLine("IMethodCallMessage");
   }
   if (myMessage is IMethodReturnMessage)
   {
      Console.WriteLine("IMethodReturnMessage");
   }
   if (myMessage is IConstructionCallMessage)
   {
      // Initialize a new instance of remote object
      IConstructionReturnMessage myIConstructionReturnMessage =
         this.InitializeServerObject((IConstructionCallMessage)myMessage);
      ConstructionResponse constructionResponse = new
         ConstructionResponse(null,(IMethodCallMessage) myMessage);
      return constructionResponse;
   }
   IDictionary myIDictionary = myMessage.Properties;
   IMessage returnMessage;
   myIDictionary["__Uri"] = myUri;

   // Synchronously dispatch messages to server.
   returnMessage = ChannelServices.SyncDispatchMessage(myMessage);
   // Pushing return value and OUT parameters back onto stack.
   IMethodReturnMessage myMethodReturnMessage = (IMethodReturnMessage)returnMessage;
   return returnMessage;
}
Public Overrides Function Invoke(myMessage As IMessage) As IMessage
   Console.WriteLine("MyProxy 'Invoke method' Called...")
   If TypeOf myMessage Is IMethodCallMessage Then
      Console.WriteLine("IMethodCallMessage")
   End If
   If TypeOf myMessage Is IMethodReturnMessage Then
      Console.WriteLine("IMethodReturnMessage")
   End If
   If TypeOf myMessage Is IConstructionCallMessage Then
      ' Initialize a new instance of remote object
      Dim myIConstructionReturnMessage As IConstructionReturnMessage = _
            Me.InitializeServerObject(CType(myMessage, IConstructionCallMessage))
      Dim constructionResponse As _
            New ConstructionResponse(Nothing, CType(myMessage, IMethodCallMessage))
      Return constructionResponse
   End If
   Dim myIDictionary As IDictionary = myMessage.Properties
   Dim returnMessage As IMessage
   myIDictionary("__Uri") = myUri
   ' Synchronously dispatch messages to server.
   returnMessage = ChannelServices.SyncDispatchMessage(myMessage)
   ' Pushing return value and OUT parameters back onto stack.
   Dim myMethodReturnMessage As IMethodReturnMessage = _
         CType(returnMessage, IMethodReturnMessage)
   Return returnMessage
End Function 'Invoke

注解

调用 支持的 RealProxy 透明代理时,它会将调用委托给 Invoke 方法。 方法 Invoke 将 参数中的 msg 消息转换为 , IMethodCallMessage并将其发送到由 的当前实例表示的 RealProxy远程对象。

参数 IMessage 通过 IMessage.Properties 属性提供字典。 字典包含有关方法调用的名称/值对信息,例如调用的方法的名称及其参数。

适用于