Op Englesch liesen Editéieren

Deelen iwwer


RealProxy Class

Definition

Provides base functionality for proxies.

C#
public abstract class RealProxy
C#
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class RealProxy
C#
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public abstract class RealProxy
Inheritance
RealProxy
Attributes

Examples

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

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

Remarks

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.

Notiz

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 Implementers

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

Constructors

RealProxy()

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

RealProxy(Type, IntPtr, Object)

Initializes a new instance of the RealProxy class.

RealProxy(Type)

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

Methods

AttachServer(MarshalByRefObject)

Attaches the current proxy instance to the specified remote MarshalByRefObject.

CreateObjRef(Type)

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

DetachServer()

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

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetCOMIUnknown(Boolean)

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

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext)

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

GetProxiedType()

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

GetStubData(RealProxy)

Retrieves stub data that is stored for the specified proxy.

GetTransparentProxy()

Returns the transparent proxy for the current instance of RealProxy.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetUnwrappedServer()

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

InitializeServerObject(IConstructionCallMessage)

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

Invoke(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.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SetCOMIUnknown(IntPtr)

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

SetStubData(RealProxy, Object)

Sets the stub data for the specified proxy.

SupportsInterface(Guid)

Requests a COM interface with the specified ID.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

Produkt Versiounen
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1