G
Guest
Is there a proper way to use the proxy classes to set up a proxy for a local object?
The code below is what I have tried. This seems at first to work, as the object I create is a transparent proxy, however, my overridden Invoke() is never called after the initial construction
I tried removing the attribute, and creating an instance of the proxy directly. This worked, however, at certain points in code execution the object returned would no longer be a transparent proxy, and instead the actual object itself. This at first seemed to only happen when passing the object to a method via the "this" keyword inside of the object. However, more testing showed that this was happening at other times as well
Is there a way to intercept all calls to a class? This is neccassary in my project to insure that an object written by any author cannot be used after it is no longer valid, since we are unable to delete objects explicitly.
Thank
[Master.MProxy
public abstract class Master : ContextBoundObjec
[AttributeUsage(AttributeTargets.Class)
internal class MProxyAttribute : ProxyAttribut
public override MarshalByRefObject CreateInstance(Type type
MarshalByRefObject m = base.CreateInstance(type)
MasterProxy proxy = new MasterProxy(type, m)
return (MarshalByRefObject)proxy.GetTransparentProxy()
/// <summary
/// Intercepts calls to make sure the object is valid
/// </summary
internal class MasterProxy : RealProx
private Master proxyObject
public MasterProxy(Type type, MarshalByRefObject obj) : base(type
proxyObject = (Master)obj
public override IMessage Invoke(IMessage message
if(message is IConstructionCallMessage
IConstructionCallMessage ccm = (IConstructionCallMessage)message
//initialize the proxy objec
return base.InitializeServerObject(ccm)
IMethodCallMessage methodMessage = (IMethodCallMessage)message
string methodName = methodMessage.MethodBase.Name
return RemotingServices.ExecuteMessage(proxyObject, methodMessage)
}
The code below is what I have tried. This seems at first to work, as the object I create is a transparent proxy, however, my overridden Invoke() is never called after the initial construction
I tried removing the attribute, and creating an instance of the proxy directly. This worked, however, at certain points in code execution the object returned would no longer be a transparent proxy, and instead the actual object itself. This at first seemed to only happen when passing the object to a method via the "this" keyword inside of the object. However, more testing showed that this was happening at other times as well
Is there a way to intercept all calls to a class? This is neccassary in my project to insure that an object written by any author cannot be used after it is no longer valid, since we are unable to delete objects explicitly.
Thank
[Master.MProxy
public abstract class Master : ContextBoundObjec
[AttributeUsage(AttributeTargets.Class)
internal class MProxyAttribute : ProxyAttribut
public override MarshalByRefObject CreateInstance(Type type
MarshalByRefObject m = base.CreateInstance(type)
MasterProxy proxy = new MasterProxy(type, m)
return (MarshalByRefObject)proxy.GetTransparentProxy()
/// <summary
/// Intercepts calls to make sure the object is valid
/// </summary
internal class MasterProxy : RealProx
private Master proxyObject
public MasterProxy(Type type, MarshalByRefObject obj) : base(type
proxyObject = (Master)obj
public override IMessage Invoke(IMessage message
if(message is IConstructionCallMessage
IConstructionCallMessage ccm = (IConstructionCallMessage)message
//initialize the proxy objec
return base.InitializeServerObject(ccm)
IMethodCallMessage methodMessage = (IMethodCallMessage)message
string methodName = methodMessage.MethodBase.Name
return RemotingServices.ExecuteMessage(proxyObject, methodMessage)
}