RealProxy Class
Collapse the table of content
Expand the table of content

RealProxy Class

 

Provides base functionality for proxies.

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

System.Object
  System.Runtime.Remoting.Proxies.RealProxy

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

NameDescription
System_CAPS_protmethodRealProxy()

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

System_CAPS_protmethodRealProxy(Type)

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.

NameDescription
System_CAPS_protmethodAttachServer(MarshalByRefObject)

Attaches the current proxy instance to the specified remote MarshalByRefObject.

System_CAPS_pubmethodCreateObjRef(Type)

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

System_CAPS_protmethodDetachServer()

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

System_CAPS_pubmethodEquals(Object)

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

System_CAPS_protmethodFinalize()

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

System_CAPS_pubmethodGetCOMIUnknown(Boolean)

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

System_CAPS_pubmethodGetHashCode()

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.

System_CAPS_pubmethodGetProxiedType()

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

System_CAPS_pubmethodSystem_CAPS_staticGetStubData(RealProxy)

Retrieves stub data that is stored for the specified proxy.

System_CAPS_pubmethodGetTransparentProxy()

Returns the transparent proxy for the current instance of RealProxy.

System_CAPS_pubmethodGetType()

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

System_CAPS_protmethodGetUnwrappedServer()

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

System_CAPS_pubmethodInitializeServerObject(IConstructionCallMessage)

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

System_CAPS_pubmethodInvoke(IMessage)

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.

System_CAPS_protmethodMemberwiseClone()

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

System_CAPS_pubmethodSetCOMIUnknown(IntPtr)

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.

System_CAPS_pubmethodSupportsInterface(Guid)

Requests a COM interface with the specified ID.

System_CAPS_pubmethodToString()

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.

System_CAPS_noteNote

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;   

   [PermissionSet(SecurityAction.LinkDemand)]
   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");
      Console.WriteLine("");

      if (myIMessage is IMethodCallMessage)
         Console.WriteLine("IMethodCallMessage");

      if (myIMessage is IMethodReturnMessage)
         Console.WriteLine("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, 
            myIDictionaryEnumerator.Value);
         if (myKeyName == "__Args")
         {
            Object[] myObjectArray = (Object[])myValue;
            for (int aIndex = 0; aIndex < myObjectArray.Length; aIndex++)
               Console.WriteLine("\t\targ: {0} myValue: {1}", aIndex, 
                  myObjectArray[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, 
                  myObjectArray[aIndex]);
         }
      }

      IMessage myReturnMessage;

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

      Console.WriteLine("ChannelServices.SyncDispatchMessage");
      myReturnMessage = ChannelServices.SyncDispatchMessage(myIMessage);

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

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

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

      return myReturnMessage;
   }
}

SecurityPermission

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

SecurityPermission

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
Show:
© 2016 Microsoft