I got a little problem I can't figure out. I have a server side MarshalByRefObject that I'm trying to wrap a transparent proxy around on the client side. Here's the setup:
public class ClientProgram {
public static void Main( string[] args ) {
ITest test = (ITest)Activator.GetObject( typeof( ITest ), "http://127.0.0.1:8765/Test.rem" );
test = (ITest)new MyProxy( test ).GetTransparentProxy();
test.Foo();
}
}
public class MyProxy : RealProxy {
private MarshalByRefObject _object;
public MyProxy( ITest pInstance )
: base( pInstance.GetType() ) {
_object = (MarshalByRefObject)pInstance;
}
public override IMessage Invoke( IMessage msg ) {
return RemotingServices.ExecuteMessage( _object, (IMethodCallMessage)msg );
}
}
The problem is that the call to RemotingServices.ExecuteMethod, an exception is thrown with the message "ExecuteMessage can be called only from the native context of the object.". Can anyone point out how to get this to work correctly? I need to inject some code before and after the method calls on remote objects. Cheers!