RealProxy Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Provides base functionality for proxies.

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


	Flags = SecurityPermissionFlag.Infrastructure)]
public abstract class RealProxy


Initializes a new instance of the RealProxy class with default values.


Initializes a new instance of the RealProxy class that represents a remote object of the specified Type.

System_CAPS_protmethodRealProxy(Type, IntPtr, Object)

Initializes a new instance of the RealProxy class.


Attaches the current proxy instance to the specified remote MarshalByRefObject.


Creates an ObjRef for the specified object type, and registers it with the remoting infrastructure as a client-activated object.


Detaches the current proxy instance from the remote server object that it represents.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Requests an unmanaged reference to the object represented by the current proxy instance.


Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetObjectData(SerializationInfo, StreamingContext)

Adds the transparent proxy of the object represented by the current instance of RealProxy to the specified SerializationInfo.


Returns the Type of the object that the current instance of RealProxy represents.


Retrieves stub data that is stored for the specified proxy.


Returns the transparent proxy for the current instance of RealProxy.


Gets the Type of the current instance.(Inherited from Object.)


Returns the server object that is represented by the current proxy instance.


Initializes a new instance of the object Type of the remote object that the current instance of RealProxy represents with the specified IConstructionCallMessage.


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.


Creates a shallow copy of the current Object.(Inherited from Object.)


Stores an unmanaged proxy of the object that is represented by the current instance.

System_CAPS_pubmethodSystem_CAPS_staticSetStubData(RealProxy, Object)

Sets the stub data for the specified proxy.


Requests a COM interface with the specified ID.


Returns 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;


For operating with infrastructure code. Demand value: SecurityAction.LinkDemand; Permission Value: SecurityPermissionFlag.Infrastructure


For operating with infrastructure code. Demand value: SecurityAction.InheritanceDemand; Permission Value: SecurityPermissionFlag.Infrastructure

.NET Framework
Available since 1.1

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

Return to top