/
remoting4.cs
executable file
·160 lines (135 loc) · 3.18 KB
/
remoting4.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Threading;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Channels;
using System.Runtime.Serialization;
namespace RemotingTest
{
class MyProxy : RealProxy
{
readonly MarshalByRefObject target;
public MyProxy (MarshalByRefObject target) : base (target.GetType())
{
this.target = target;
}
public override IMessage Invoke (IMessage request)
{
IMethodCallMessage call = (IMethodCallMessage)request;
Console.WriteLine ("Invoke " + call.MethodName);
Console.Write ("ARGS(");
for (int i = 0; i < call.ArgCount; i++)
{
if (i != 0)
Console.Write (", ");
Console.Write (call.GetArgName (i) + " " +
call.GetArg (i));
}
Console.WriteLine (")");
Console.Write ("INARGS(");
for (int i = 0; i < call.InArgCount; i++)
{
if (i != 0)
Console.Write (", ");
Console.Write (call.GetInArgName (i) + " " +
call.GetInArg (i));
}
Console.WriteLine (")");
IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
Console.Write ("RESARGS(");
for (int i = 0; i < res.ArgCount; i++)
{
if (i != 0)
Console.Write (", ");
Console.Write (res.GetArgName (i) + " " +
res.GetArg (i));
}
Console.WriteLine (")");
Console.Write ("RESOUTARGS(");
for (int i = 0; i < res.OutArgCount; i++)
{
if (i != 0)
Console.Write (", ");
Console.Write (res.GetOutArgName (i) + " " +
res.GetOutArg (i));
}
Console.WriteLine (")");
return res;
}
}
class R2
{
string sTest;
public R2()
{
sTest = "R2";
}
public void Print()
{
Console.WriteLine(sTest);
}
}
[Serializable]
class R2_MBV
{
string sTest;
public R2_MBV()
{
sTest = "R2";
}
public string Data
{
get
{
return sTest;
}
}
}
class R1 : MarshalByRefObject
{
public R2 TestMBV() {
return new R2();
}
}
class Class1
{
static int Main(string[] args)
{
Console.WriteLine("test " + AppDomain.CurrentDomain.FriendlyName);
AppDomain app2 = AppDomain.CreateDomain("2");
if (!RemotingServices.IsTransparentProxy(app2))
return 1;
ObjectHandle o = AppDomain.CurrentDomain.CreateInstance(typeof(R1).Assembly.FullName, typeof(R1).FullName);
R1 myobj = (R1) o.Unwrap();
// should not be a proxy in our domain..
if (RemotingServices.IsTransparentProxy(myobj))
{
Console.WriteLine("CreateInstance return TP for in our current domain");
return 2;
}
o = app2.CreateInstance(typeof(R1).Assembly.FullName, typeof(R1).FullName);
Console.WriteLine("type: " + o.GetType().ToString());
myobj = (R1) o.Unwrap();
if (!RemotingServices.IsTransparentProxy(myobj))
return 3;
Console.WriteLine("unwrapped type: " + myobj.GetType().ToString());
R2 r2 = null;
bool bSerExc = false;
// this should crash
try
{
r2 = myobj.TestMBV();
}
catch (SerializationException)
{
bSerExc = true;
}
if (!bSerExc)
return 4;
Console.WriteLine("test-ok");
return 0;
}
}
}