2 using System.Threading;
3 using System.Runtime.InteropServices;
4 using System.Runtime.Remoting;
5 using System.Runtime.Remoting.Messaging;
6 using System.Runtime.Remoting.Proxies;
7 using System.Runtime.Remoting.Channels;
8 using System.Runtime.Serialization;
10 namespace RemotingTest
\r
12 class MyProxy : RealProxy
\r
14 readonly MarshalByRefObject target;
16 public MyProxy (MarshalByRefObject target) : base (target.GetType())
\r
21 public override IMessage Invoke (IMessage request)
\r
23 IMethodCallMessage call = (IMethodCallMessage)request;
24 Console.WriteLine ("Invoke " + call.MethodName);
26 Console.Write ("ARGS(");
27 for (int i = 0; i < call.ArgCount; i++)
\r
31 Console.Write (call.GetArgName (i) + " " +
34 Console.WriteLine (")");
35 Console.Write ("INARGS(");
36 for (int i = 0; i < call.InArgCount; i++)
\r
40 Console.Write (call.GetInArgName (i) + " " +
43 Console.WriteLine (")");
45 IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
47 Console.Write ("RESARGS(");
48 for (int i = 0; i < res.ArgCount; i++)
\r
52 Console.Write (res.GetArgName (i) + " " +
55 Console.WriteLine (")");
57 Console.Write ("RESOUTARGS(");
58 for (int i = 0; i < res.OutArgCount; i++)
\r
62 Console.Write (res.GetOutArgName (i) + " " +
65 Console.WriteLine (")");
79 public void Print()
\r
81 Console.WriteLine(sTest);
103 class R1 : MarshalByRefObject
\r
105 public R2 TestMBV() {
\r
112 static int Main(string[] args)
\r
114 Console.WriteLine("test " + AppDomain.CurrentDomain.FriendlyName);
\r
115 AppDomain app2 = AppDomain.CreateDomain("2");
\r
117 if (!RemotingServices.IsTransparentProxy(app2))
120 ObjectHandle o = AppDomain.CurrentDomain.CreateInstance(typeof(R1).Assembly.FullName, typeof(R1).FullName);
\r
121 R1 myobj = (R1) o.Unwrap();
\r
123 // should not be a proxy in our domain..
124 if (RemotingServices.IsTransparentProxy(myobj))
126 Console.WriteLine("CreateInstance return TP for in our current domain");
130 o = app2.CreateInstance(typeof(R1).Assembly.FullName, typeof(R1).FullName);
\r
132 Console.WriteLine("type: " + o.GetType().ToString());
\r
134 myobj = (R1) o.Unwrap();
\r
135 if (!RemotingServices.IsTransparentProxy(myobj))
138 Console.WriteLine("unwrapped type: " + myobj.GetType().ToString());
\r
141 bool bSerExc = false;
146 r2 = myobj.TestMBV();
148 catch (SerializationException)
156 Console.WriteLine("test-ok");