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 new HttpChannel (8086);
24 RemotingServices.Marshal (new Service (), "test");
26 Service remObj = (Service) RemotingServices.Connect (
27 typeof (Service), "http://localhost:8086/test");
30 remObj.Test (out list);
31 // it's of type 'ObjRef' instead of 'Service':
32 Assert.IsTrue (list [0] is Service);
35 remObj.Test (out array);
38 public class Service : MarshalByRefObject
40 public Service Test (out Service[] a)
42 Service obj = new Service ();
43 a = new Service [] { obj };
45 // return null or return otherObj works
48 public Service Test (out ArrayList a)
51 Service obj = new Service ();
54 // return null or return otherObj works
59 //Bug 321420 - SoapReader fails to deserialize some method calls
61 public class Bug321420 : MarshalByRefObject
65 public void Method (string p1, string p2)
72 var port = NetworkHelpers.FindFreePort ();
73 channel = new HttpChannel (port);
74 ChannelServices.RegisterChannel (channel);
75 RemotingConfiguration.RegisterWellKnownServiceType
76 (typeof (Bug321420),"Server.soap", WellKnownObjectMode.Singleton);
78 Bug321420 s = (Bug321420) Activator.GetObject (typeof
79 (Bug321420), $"http://localhost:{port}/Server.soap");
81 // this works: s.Method ("a", "b");
89 ChannelServices.UnregisterChannel (channel);
93 //Bug 315570 - Remoting over HTTP fails when returning a null reference.
95 public class Bug315570
100 [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.")]
103 Foo foo = (Foo) Activator.GetObject (typeof (Foo),
104 $"http://localhost:{server.HttpPort}/Test");
106 Bar bar = foo.Login ();
114 AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
115 server = (Server) domain.CreateInstanceAndUnwrap
116 (typeof (Server).Assembly.FullName, typeof (Server).FullName);
120 [TestFixtureTearDown]
126 public class Foo: MarshalByRefObject
134 public class Bar: MarshalByRefObject
136 public void Foobar ()
138 // Console.WriteLine("Bar::foo()");
142 public class Server : MarshalByRefObject
148 HttpPort = NetworkHelpers.FindFreePort ();
149 c = new HttpChannel (HttpPort);
150 ChannelServices.RegisterChannel (c);
152 Type t = typeof(Foo);
153 RemotingConfiguration.RegisterWellKnownServiceType (t, "Test",
154 WellKnownObjectMode.SingleCall);
159 c.StopListening (null);
160 ChannelServices.UnregisterChannel (c);
163 public int HttpPort { get; private set; }
167 //Bug 315170 - exception thrown in remoting if interface parameter names differ from the impelmentation method parameter names
169 public class Bug315170
177 channel = new HttpChannel (0);
178 ChannelServices.RegisterChannel (channel);
179 MarshalByRefObject obj = (MarshalByRefObject) RemotingServices.Connect (
181 $"http://localhost:{server.HttpPort}/MyEndPoint");
182 IFactorial cal = (IFactorial) obj;
183 Assert.AreEqual (cal.CalculateFactorial (4), 24);
189 AppDomain domain = BaseCallTest.CreateDomain ("testdomain");
190 server = (Server) domain.CreateInstanceAndUnwrap
191 (typeof (Server).Assembly.FullName, typeof (Server).FullName);
195 [TestFixtureTearDown]
200 ChannelServices.UnregisterChannel (channel);
203 public interface IFactorial
205 // With this line everything works
206 //ulong CalculateFactorial(uint a);
207 // With this line it doesn't
208 ulong CalculateFactorial(uint b);
212 public class Server : MarshalByRefObject
218 HttpPort = NetworkHelpers.FindFreePort ();
219 c = new HttpChannel (HttpPort);
220 ChannelServices.RegisterChannel (c);
222 Type t = typeof(Calculator);
223 RemotingConfiguration.RegisterWellKnownServiceType (t, "MyEndPoint",
224 WellKnownObjectMode.Singleton);
229 c.StopListening (null);
230 ChannelServices.UnregisterChannel (c);
233 public int HttpPort { get; private set; }
236 public class Calculator : MarshalByRefObject, IFactorial
238 public ulong CalculateFactorial (uint a)
241 for (uint i=1 ; i<=a; i++)