Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
RealProxy Class
RealProxy Methods
 Invoke Method
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
RealProxy..::.Invoke Method

Updated: November 2007

When overridden in a derived class, invokes the method that is specified in the provided IMessage on the remote object that is represented by the current instance.

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

Visual Basic (Declaration)
Public MustOverride Function Invoke ( _
    msg As IMessage _
) As IMessage
Visual Basic (Usage)
Dim instance As RealProxy
Dim msg As IMessage
Dim returnValue As IMessage

returnValue = instance.Invoke(msg)
C#
public abstract IMessage Invoke(
    IMessage msg
)
Visual C++
public:
virtual IMessage^ Invoke(
    IMessage^ msg
) abstract
J#
public abstract IMessage Invoke(
    IMessage msg
)
JScript
public abstract function Invoke(
    msg : IMessage
) : IMessage

Parameters

msg
Type: System.Runtime.Remoting.Messaging..::.IMessage

A IMessage that contains a IDictionary of information about the method call.

Return Value

Type: System.Runtime.Remoting.Messaging..::.IMessage

The message returned by the invoked method, containing the return value and any out or ref parameters.

When the transparent proxy that is backed by the RealProxy is called, it delegates the calls to the Invoke method. The Invoke method transforms the message in the msg parameter into a IMethodCallMessage, and sends it to the remote object that is represented by the current instance of RealProxy.

The IMessage parameter provides a dictionary through the IMessage..::.Properties property. The dictionary contains name/value pairs of information about the method call, such as the name of the method called and its parameters.

Visual Basic
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

C#
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;
}

Visual C++
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;
}

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker