Пример #1
0
        public void GetObjRefForProxy()
        {
            TcpChannel chn = null;

            try
            {
                chn = new TcpChannel(1239);
                ChannelServices.RegisterChannel(chn);

                // Register le factory as a SAO
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);

                MarshalObjectFactory objFactory = (MarshalObjectFactory)Activator.GetObject(typeof(MarshalObjectFactory), "tcp://localhost:1239/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");

                // Get a new "CAO"
                MarshalObject objRem = objFactory.GetNewMarshalObject();

                ObjRef objRefRem = RemotingServices.GetObjRefForProxy((MarshalByRefObject)objRem);

                Assert.IsTrue(objRefRem != null, "#A11");
            }
            finally
            {
                if (chn != null)
                {
                    ChannelServices.UnregisterChannel(chn);
                }
            }
        }
        public void GetObjRefForProxy()
        {
            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 {
                // Register le factory as a SAO
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObjectFactory), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap", WellKnownObjectMode.Singleton);

                MarshalObjectFactory objFactory = (MarshalObjectFactory)Activator.GetObject(typeof(MarshalObjectFactory), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.Factory.soap");

                // Get a new "CAO"
                MarshalObject objRem = objFactory.GetNewMarshalObject();

                ObjRef objRefRem = RemotingServices.GetObjRefForProxy((MarshalByRefObject)objRem);

                Assert.IsNotNull(objRefRem, "#A11");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }