RealProxy Class
Provides base functionality for proxies.
Assembly: mscorlib (in mscorlib.dll)
'Declaration <ComVisibleAttribute(True)> _ <SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _ <SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags := SecurityPermissionFlag.Infrastructure)> _ Public MustInherit Class RealProxy 'Usage Dim instance As RealProxy
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 Class MyProxy Inherits RealProxy Private myURIString As String Private myMarshalByRefObject As MarshalByRefObject <PermissionSet(SecurityAction.LinkDemand)> _ Public Sub New(ByVal myType As Type) MyBase.New(myType) ' RealProxy uses the Type to generate a transparent proxy. myMarshalByRefObject = CType(Activator.CreateInstance(myType), MarshalByRefObject) ' Get 'ObjRef', for transmission serialization between application domains. Dim myObjRef As ObjRef = RemotingServices.Marshal(myMarshalByRefObject) ' Get the 'URI' property of 'ObjRef' and store it. myURIString = myObjRef.URI Console.WriteLine("URI :{0}", myObjRef.URI) End Sub 'New <SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags:=SecurityPermissionFlag.Infrastructure)> _ Public Overrides Function Invoke(ByVal myIMessage As IMessage) As IMessage Console.WriteLine("MyProxy.Invoke Start") Console.WriteLine("") If TypeOf myIMessage Is IMethodCallMessage Then Console.WriteLine("IMethodCallMessage") End If If TypeOf myIMessage Is IMethodReturnMessage Then Console.WriteLine("IMethodReturnMessage") End If Dim msgType As Type msgType = CObj(myIMessage).GetType Console.WriteLine("Message Type: {0}", msgType.ToString()) Console.WriteLine("Message Properties") Dim myIDictionary As IDictionary = myIMessage.Properties ' Set the '__Uri' property of 'IMessage' to 'URI' property of 'ObjRef'. myIDictionary("__Uri") = myURIString Dim myIDictionaryEnumerator As IDictionaryEnumerator = CType(myIDictionary.GetEnumerator(), _ IDictionaryEnumerator) While myIDictionaryEnumerator.MoveNext() Dim myKey As Object = myIDictionaryEnumerator.Key Dim myKeyName As String = myKey.ToString() Dim myValue As Object = myIDictionaryEnumerator.Value Console.WriteLine(ControlChars.Tab + "{0} : {1}", myKeyName, myIDictionaryEnumerator.Value) If myKeyName = "__Args" Then Dim myObjectArray As Object() = CType(myValue, Object()) Dim aIndex As Integer For aIndex = 0 To myObjectArray.Length - 1 Console.WriteLine(ControlChars.Tab + ControlChars.Tab + "arg: {0} myValue: {1}", _ aIndex, myObjectArray(aIndex)) Next aIndex End If If myKeyName = "__MethodSignature" And Not Nothing Is myValue Then Dim myObjectArray As Object() = CType(myValue, Object()) Dim aIndex As Integer For aIndex = 0 To myObjectArray.Length - 1 Console.WriteLine(ControlChars.Tab + ControlChars.Tab + "arg: {0} myValue: {1}", _ aIndex, myObjectArray(aIndex)) Next aIndex End If End While Dim myReturnMessage As IMessage myIDictionary("__Uri") = myURIString Console.WriteLine("__Uri {0}", myIDictionary("__Uri")) Console.WriteLine("ChannelServices.SyncDispatchMessage") myReturnMessage = ChannelServices.SyncDispatchMessage(CObj(myIMessage)) ' Push return value and OUT parameters back onto stack. Dim myMethodReturnMessage As IMethodReturnMessage = CType(myReturnMessage, IMethodReturnMessage) Console.WriteLine("IMethodReturnMessage.ReturnValue: {0}", myMethodReturnMessage.ReturnValue) Console.WriteLine("MyProxy.Invoke - Finish") Return myReturnMessage End Function 'Invoke End Class 'MyProxy
// Create a custom 'RealProxy'.
public __gc class MyProxy : public RealProxy
{
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(S"URI :{0}", myObjRef->URI);
}
IMessage* Invoke(IMessage* myIMessage)
{
Console::WriteLine(S"MyProxy.Invoke Start");
Console::WriteLine(S"");
if (dynamic_cast<IMethodCallMessage*>(myIMessage))
Console::WriteLine(S"IMethodCallMessage");
if (dynamic_cast<IMethodReturnMessage*>(myIMessage))
Console::WriteLine(S"IMethodReturnMessage");
Type* msgType = myIMessage->GetType();
Console::WriteLine(S"Message Type: {0}", msgType);
Console::WriteLine(S"Message Properties");
IDictionary* myIDictionary = myIMessage->Properties;
// Set the '__Uri' property of 'IMessage' to 'URI' property of 'ObjRef'.
myIDictionary->Item[S"__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(S"\t{0} : {1}", myKeyName,
myIDictionaryEnumerator->Value);
if (myKeyName->Equals(S"__Args"))
{
Object* myObjectArray[] = (Object*[])myValue;
for (int aIndex = 0; aIndex < myObjectArray->Length; aIndex++)
Console::WriteLine(S"\t\targ: {0} myValue: {1}", __box(aIndex),
myObjectArray[aIndex]);
}
if ((myKeyName->Equals(S"__MethodSignature")) && (0 != myValue))
{
Object* myObjectArray[] = (Object*[])myValue;
for (int aIndex = 0; aIndex < myObjectArray->Length; aIndex++)
Console::WriteLine(S"\t\targ: {0} myValue: {1}", __box(aIndex),
myObjectArray[aIndex]);
}
}
IMessage* myReturnMessage;
myIDictionary->Item[S"__Uri"] = myURIString;
Console::WriteLine(S"__Uri {0}", myIDictionary->Item[S"__Uri"]);
Console::WriteLine(S"ChannelServices.SyncDispatchMessage");
myReturnMessage = ChannelServices::SyncDispatchMessage(myIMessage);
// Push return value and OUT parameters back onto stack.
IMethodReturnMessage* myMethodReturnMessage = dynamic_cast<IMethodReturnMessage*>(myReturnMessage);
Console::WriteLine(S"IMethodReturnMessage.ReturnValue: {0}",
myMethodReturnMessage->ReturnValue);
Console::WriteLine(S"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, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: