Export (0) Print
Expand All

RealProxy.Invoke Method

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)

public abstract IMessage Invoke(
	IMessage 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.

public override IMessage Invoke(IMessage myMessage)
   Console.WriteLine("MyProxy 'Invoke method' Called...");
   if (myMessage is IMethodCallMessage)
   if (myMessage is IMethodReturnMessage)
   if (myMessage is IConstructionCallMessage)
      // Initialize a new instance of remote object
      IConstructionReturnMessage myIConstructionReturnMessage = 
      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;

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft