public void IsOneWay()
        {
            TcpChannel chn = null;

            try
            {
                chn = new TcpChannel(1238);
                ChannelServices.RegisterChannel(chn);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);

                MarshalObject objRem = (MarshalObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1238/MarshalObject.rem");

                Assert.IsTrue(RemotingServices.IsTransparentProxy(objRem), "#A10.1");

                objRem.Method1();
                Thread.Sleep(20);
                Assert.IsTrue(!MarshalObject.IsMethodOneWay, "#A10.2");
                objRem.Method3();
                Thread.Sleep(20);
                Assert.IsTrue(MarshalObject.IsMethodOneWay, "#A10.2");
            }
            finally
            {
                if (chn != null)
                {
                    ChannelServices.UnregisterChannel(chn);
                }
            }
        }
Example #2
0
        public void ExecuteMessage()
        {
            var        port = NetworkHelpers.FindFreePort();
            TcpChannel chn  = new TcpChannel(port);

            ChannelServices.RegisterChannel(chn);
            try {
                MarshalObject objMarshal = NewMarshalObject();
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall);

                // use a proxy to catch the Message
                MyProxy proxy = new MyProxy(typeof(MarshalObject), (MarshalObject)Activator.GetObject(typeof(MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri));

                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                objRem.Method1();

                // Tests RemotingServices.GetMethodBaseFromMethodMessage()
                Assert.AreEqual("Method1", proxy.MthBase.Name, "#A09");
                Assert.IsFalse(proxy.IsMethodOverloaded, "#A09.1");

                objRem.Method2();
                Assert.IsTrue(proxy.IsMethodOverloaded, "#A09.2");

                // Tests RemotingServices.ExecuteMessage();
                // If ExecuteMessage does it job well, Method1 should be called 2 times
                Assert.AreEqual(2, MarshalObject.Called, "#A10");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Example #3
0
        public void ExecuteMessage()
        {
            TcpChannel chn = new TcpChannel(1235);

            ChannelServices.RegisterChannel(chn);
            try {
                MarshalObject objMarshal = NewMarshalObject();
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), objMarshal.Uri, WellKnownObjectMode.SingleCall);

                // use a proxy to catch the Message
                MyProxy proxy = new MyProxy(typeof(MarshalObject), (MarshalObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1235/" + objMarshal.Uri));

                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                objRem.Method1();

                // Tests RemotingServices.GetMethodBaseFromMethodMessage()
                AssertEquals("#A09", "Method1", proxy.MthBase.Name);
                Assert("#A09.1", !proxy.IsMethodOverloaded);

                objRem.Method2();
                Assert("#A09.2", proxy.IsMethodOverloaded);

                // Tests RemotingServices.ExecuteMessage();
                // If ExecuteMessage does it job well, Method1 should be called 2 times
                AssertEquals("#A10", 2, MarshalObject.Called);
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
        public void IsOneWay()
        {
            var         port  = NetworkHelpers.FindFreePort();
            IDictionary props = new Hashtable();

            props ["port"]   = port;
            props ["bindTo"] = "127.0.0.1";
            TcpChannel chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);
            try {
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);

                MarshalObject objRem = (MarshalObject)Activator.GetObject(typeof(MarshalObject), $"tcp://localhost:{port}/MarshalObject.rem");

                Assert.IsTrue(RemotingServices.IsTransparentProxy(objRem), "#A10.1");

                objRem.Method1();
                Thread.Sleep(20);
                Assert.IsFalse(MarshalObject.IsMethodOneWay, "#A10.2");
                objRem.Method3();
                Thread.Sleep(20);
                Assert.IsTrue(MarshalObject.IsMethodOneWay, "#A10.3");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }