This documentation is archived and is not being maintained.

RealProxy Class

Provides base functionality for proxies.


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

[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public abstract class RealProxy

The RealProxy type exposes the following members.

Protected methodRealProxy()Initializes a new instance of the RealProxy class with default values.
Protected methodRealProxy(Type)Initializes a new instance of the RealProxy class that represents a remote object of the specified Type.
Protected methodRealProxy(Type, IntPtr, Object)Initializes a new instance of the RealProxy class.

Protected methodAttachServerAttaches the current proxy instance to the specified remote MarshalByRefObject.
Public methodCreateObjRefCreates an ObjRef for the specified object type, and registers it with the remoting infrastructure as a client-activated object.
Protected methodDetachServerDetaches the current proxy instance from the remote server object that it represents.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetCOMIUnknownRequests an unmanaged reference to the object represented by the current proxy instance.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetObjectDataAdds the transparent proxy of the object represented by the current instance of RealProxy to the specified SerializationInfo.
Public methodGetProxiedTypeReturns the Type of the object that the current instance of RealProxy represents.
Public methodStatic memberGetStubDataRetrieves stub data that is stored for the specified proxy.
Public methodGetTransparentProxyReturns the transparent proxy for the current instance of RealProxy.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodGetUnwrappedServerReturns the server object that is represented by the current proxy instance.
Public methodInitializeServerObjectInitializes a new instance of the object Type of the remote object that the current instance of RealProxy represents with the specified IConstructionCallMessage.
Public methodInvokeWhen 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.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSetCOMIUnknownStores an unmanaged proxy of the object that is represented by the current instance.
Public methodStatic memberSetStubDataSets the stub data for the specified proxy.
Public methodSupportsInterfaceRequests a COM interface with the specified ID.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

The RealProxy class is the abstract base class from which proxies must derive.

A client that uses an object across any kind of a remoting boundary is actually using a transparent proxy for the object. The transparent proxy provides the illusion that the actual object resides in the client's space. It achieves this by forwarding calls made on it to the real object using the remoting infrastructure.

The transparent proxy is itself housed by an instance of a managed runtime class of type RealProxy. The RealProxy implements a part of the functionality that is needed to forward the operations from the transparent proxy. Note that a proxy object inherits the associated semantics of managed objects such as garbage collection, support for fields and methods, and can be extended to form new classes. The proxy has a dual nature: it acts as an object of the same class as the remote object (transparent proxy), and it is a managed object itself.

A proxy object can be used without regard to any remoting subdivisions within a AppDomain.


This class makes a link demand and an inheritance demand at the class level. A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see Link Demands and Inheritance Demands.

Notes to Inheritors

When you inherit from RealProxy, you must override the Invoke method.

// Create a custom 'RealProxy'.
public class MyProxy : RealProxy
   String myURIString;
   MarshalByRefObject myMarshalByRefObject;   

   public MyProxy(Type myType) : base(myType)
      // RealProxy uses the Type to generate a transparent proxy.
      myMarshalByRefObject = (MarshalByRefObject)Activator.CreateInstance((myType));
      // Get 'ObjRef', for transmission serialization between application domains.
      ObjRef myObjRef = RemotingServices.Marshal(myMarshalByRefObject);
      // Get the 'URI' property of 'ObjRef' and store it.
      myURIString = myObjRef.URI;
      Console.WriteLine("URI :{0}", myObjRef.URI);

   [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.Infrastructure)]
   public override IMessage Invoke(IMessage myIMessage)
      Console.WriteLine("MyProxy.Invoke Start");

      if (myIMessage is IMethodCallMessage)

      if (myIMessage is IMethodReturnMessage)

      Type msgType = myIMessage.GetType();
      Console.WriteLine("Message Type: {0}", msgType.ToString());
      Console.WriteLine("Message Properties");
      IDictionary myIDictionary = myIMessage.Properties;
      // Set the '__Uri' property of 'IMessage' to 'URI' property of 'ObjRef'.
      myIDictionary["__Uri"] = myURIString;
      IDictionaryEnumerator myIDictionaryEnumerator = 
         (IDictionaryEnumerator) myIDictionary.GetEnumerator();

      while (myIDictionaryEnumerator.MoveNext())
         Object myKey = myIDictionaryEnumerator.Key;
         String myKeyName = myKey.ToString();
         Object myValue = myIDictionaryEnumerator.Value;

         Console.WriteLine("\t{0} : {1}", myKeyName, 
         if (myKeyName == "__Args")
            Object[] myObjectArray = (Object[])myValue;
            for (int aIndex = 0; aIndex < myObjectArray.Length; aIndex++)
               Console.WriteLine("\t\targ: {0} myValue: {1}", aIndex, 

         if ((myKeyName == "__MethodSignature") && (null != myValue))
            Object[] myObjectArray = (Object[])myValue;
            for (int aIndex = 0; aIndex < myObjectArray.Length; aIndex++)
               Console.WriteLine("\t\targ: {0} myValue: {1}", aIndex, 

      IMessage myReturnMessage;

      myIDictionary["__Uri"] = myURIString;
      Console.WriteLine("__Uri {0}", myIDictionary["__Uri"]);

      myReturnMessage = ChannelServices.SyncDispatchMessage(myIMessage);

      // Push return value and OUT parameters back onto stack.

      IMethodReturnMessage myMethodReturnMessage = (IMethodReturnMessage)
      Console.WriteLine("IMethodReturnMessage.ReturnValue: {0}", 

      Console.WriteLine("MyProxy.Invoke - Finish");

      return myReturnMessage;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.