4 using System
.Collections
;
5 using System
.Runtime
.Remoting
;
6 using System
.Runtime
.Remoting
.Channels
;
7 using System
.Runtime
.Remoting
.Channels
.Http
;
10 using MonoTests
.Helpers
;
12 namespace MonoTests
.Remoting
.Http
14 //Test for Bug 324362 - SoapFormatter cannot deserialize the same MBR twice
16 public class Bug324362
19 // [Category ("NotWorking")] // the assertion fails, and if it's removed, there's an exception
20 [Ignore ("This test somehow keeps http channel registered and then blocks any further http tests working. This also happens under .NET, so this test itself is wrong with nunit 2.4.8.")]
23 var port
= NetworkHelpers
.FindFreePort ();
24 Hashtable props
= new Hashtable ();
26 props
["bindTo"] = "127.0.0.1";
27 new HttpChannel (props
, null, null);
28 RemotingServices
.Marshal (new Service (), "test");
30 Service remObj
= (Service
) RemotingServices
.Connect (
31 typeof (Service
), $"http://127.0.0.1:{port}/test");
34 remObj
.Test (out list
);
35 // it's of type 'ObjRef' instead of 'Service':
36 Assert
.IsTrue (list
[0] is Service
);
39 remObj
.Test (out array
);
42 public class Service
: MarshalByRefObject
44 public Service
Test (out Service
[] a
)
46 Service obj
= new Service ();
47 a
= new Service
[] { obj }
;
49 // return null or return otherObj works
52 public Service
Test (out ArrayList a
)
55 Service obj
= new Service ();
58 // return null or return otherObj works
63 //Bug 321420 - SoapReader fails to deserialize some method calls
65 public class Bug321420
: MarshalByRefObject
69 public void Method (string p1
, string p2
)
76 var port
= NetworkHelpers
.FindFreePort ();
77 Hashtable props
= new Hashtable ();
79 props
["bindTo"] = "127.0.0.1";
80 channel
= new HttpChannel (props
, null, null);
81 ChannelServices
.RegisterChannel (channel
);
82 RemotingConfiguration
.RegisterWellKnownServiceType
83 (typeof (Bug321420
),"Server.soap", WellKnownObjectMode
.Singleton
);
85 Bug321420 s
= (Bug321420
) Activator
.GetObject (typeof
86 (Bug321420
), $"http://127.0.0.1:{port}/Server.soap");
88 // this works: s.Method ("a", "b");
96 ChannelServices
.UnregisterChannel (channel
);
100 //Bug 315570 - Remoting over HTTP fails when returning a null reference.
102 public class Bug315570
107 [Ignore ("This test somehow keeps http channel registered and then blocks any further http tests working. This also happens under .NET, so this test itself is wrong with nunit 2.4.8.")]
110 Foo foo
= (Foo
) Activator
.GetObject (typeof (Foo
),
111 $"http://127.0.0.1:{server.HttpPort}/Test");
113 Bar bar
= foo
.Login ();
121 AppDomain domain
= BaseCallTest
.CreateDomain ("testdomain");
122 server
= (Server
) domain
.CreateInstanceAndUnwrap
123 (typeof (Server
).Assembly
.FullName
, typeof (Server
).FullName
);
127 [TestFixtureTearDown
]
133 public class Foo
: MarshalByRefObject
141 public class Bar
: MarshalByRefObject
143 public void Foobar ()
145 // Console.WriteLine("Bar::foo()");
149 public class Server
: MarshalByRefObject
155 HttpPort
= NetworkHelpers
.FindFreePort ();
156 Hashtable props
= new Hashtable ();
157 props
["port"] = HttpPort
;
158 props
["bindTo"] = "127.0.0.1";
159 c
= new HttpChannel (props
, null, null);
160 ChannelServices
.RegisterChannel (c
);
162 Type t
= typeof(Foo
);
163 RemotingConfiguration
.RegisterWellKnownServiceType (t
, "Test",
164 WellKnownObjectMode
.SingleCall
);
169 c
.StopListening (null);
170 ChannelServices
.UnregisterChannel (c
);
173 public int HttpPort { get; private set; }
177 //Bug 315170 - exception thrown in remoting if interface parameter names differ from the impelmentation method parameter names
179 public class Bug315170
187 Hashtable props
= new Hashtable ();
189 props
["bindTo"] = "127.0.0.1";
190 channel
= new HttpChannel (props
, null, null);
191 ChannelServices
.RegisterChannel (channel
);
192 MarshalByRefObject obj
= (MarshalByRefObject
) RemotingServices
.Connect (
194 $"http://127.0.0.1:{server.HttpPort}/MyEndPoint");
195 IFactorial cal
= (IFactorial
) obj
;
196 Assert
.AreEqual (cal
.CalculateFactorial (4), 24);
202 AppDomain domain
= BaseCallTest
.CreateDomain ("testdomain");
203 server
= (Server
) domain
.CreateInstanceAndUnwrap
204 (typeof (Server
).Assembly
.FullName
, typeof (Server
).FullName
);
208 [TestFixtureTearDown
]
213 ChannelServices
.UnregisterChannel (channel
);
216 public interface IFactorial
218 // With this line everything works
219 //ulong CalculateFactorial(uint a);
220 // With this line it doesn't
221 ulong CalculateFactorial(uint b
);
225 public class Server
: MarshalByRefObject
231 HttpPort
= NetworkHelpers
.FindFreePort ();
232 Hashtable props
= new Hashtable ();
233 props
["port"] = HttpPort
;
234 props
["bindTo"] = "127.0.0.1";
235 c
= new HttpChannel (props
, null, null);
236 ChannelServices
.RegisterChannel (c
);
238 Type t
= typeof(Calculator
);
239 RemotingConfiguration
.RegisterWellKnownServiceType (t
, "MyEndPoint",
240 WellKnownObjectMode
.Singleton
);
245 c
.StopListening (null);
246 ChannelServices
.UnregisterChannel (c
);
249 public int HttpPort { get; private set; }
252 public class Calculator
: MarshalByRefObject
, IFactorial
254 public ulong CalculateFactorial (uint a
)
257 for (uint i
=1 ; i
<=a
; i
++)