RealProxy Class
Provides base functionality for proxies.
Assembly: mscorlib (in mscorlib.dll)
The RealProxy type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | RealProxy() | Initializes a new instance of the RealProxy class with default values. |
![]() | RealProxy(Type) | Initializes a new instance of the RealProxy class that represents a remote object of the specified Type. |
![]() | RealProxy(Type, IntPtr, Object) | Initializes a new instance of the RealProxy class. |
| Name | Description | |
|---|---|---|
![]() | AttachServer | Attaches the current proxy instance to the specified remote MarshalByRefObject. |
![]() | CreateObjRef | 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.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetCOMIUnknown | Requests an unmanaged reference to the object represented by the current proxy instance. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetObjectData | 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 | 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 | Initializes a new instance of the object Type of the remote object that the current instance of RealProxy represents with the specified IConstructionCallMessage. |
![]() | Invoke | 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 | Stores an unmanaged proxy of the object that is represented by the current instance. |
![]() ![]() | SetStubData | Sets the stub data for the specified proxy. |
![]() | SupportsInterface | Requests a COM interface with the specified ID. |
![]() | ToString | 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.
Note |
|---|
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. |
When you inherit from RealProxy, you must override the Invoke method.
// Create a custom 'RealProxy'. public ref class MyProxy: public RealProxy { private: String^ myURIString; MarshalByRefObject^ myMarshalByRefObject; public: MyProxy( Type^ myType ) : RealProxy( myType ) { // RealProxy uses the Type to generate a transparent proxy. myMarshalByRefObject = dynamic_cast<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 ); } virtual IMessage^ Invoke ( IMessage^ myIMessage ) override { Console::WriteLine( "MyProxy.Invoke Start" ); Console::WriteLine( "" ); if ( dynamic_cast<IMethodCallMessage^>(myIMessage) ) Console::WriteLine( "IMethodCallMessage" ); if ( dynamic_cast<IMethodReturnMessage^>(myIMessage) ) Console::WriteLine( "IMethodReturnMessage" ); Type^ msgType = myIMessage->GetType(); Console::WriteLine( "Message Type: {0}", msgType ); Console::WriteLine( "Message Properties" ); IDictionary^ myIDictionary = myIMessage->Properties; // Set the '__Uri' property of 'IMessage' to 'URI' property of 'ObjRef'. myIDictionary->default[ "__Uri" ] = myURIString; IDictionaryEnumerator^ myIDictionaryEnumerator = dynamic_cast<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->Equals( "__Args" ) ) { array<Object^>^myObjectArray = (array<Object^>^)myValue; for ( int aIndex = 0; aIndex < myObjectArray->Length; aIndex++ ) Console::WriteLine( "\t\targ: {0} myValue: {1}", aIndex, myObjectArray[ aIndex ] ); } if ( (myKeyName->Equals( "__MethodSignature" )) && (nullptr != myValue) ) { array<Object^>^myObjectArray = (array<Object^>^)myValue; for ( int aIndex = 0; aIndex < myObjectArray->Length; aIndex++ ) Console::WriteLine( "\t\targ: {0} myValue: {1}", aIndex, myObjectArray[ aIndex ] ); } } IMessage^ myReturnMessage; myIDictionary->default[ "__Uri" ] = myURIString; Console::WriteLine( "__Uri {0}", myIDictionary->default[ "__Uri" ] ); Console::WriteLine( "ChannelServices.SyncDispatchMessage" ); myReturnMessage = ChannelServices::SyncDispatchMessage( myIMessage ); // Push return value and OUT parameters back onto stack. IMethodReturnMessage^ myMethodReturnMessage = dynamic_cast<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
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.
