public void IsObjectOutOf()
        {
            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), "MarshalObject2.rem", WellKnownObjectMode.Singleton);

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

                Assert.IsTrue(RemotingServices.IsObjectOutOfAppDomain(objRem), "#A16");
                Assert.IsTrue(RemotingServices.IsObjectOutOfContext(objRem), "#A17");

                MarshalObject objMarshal = new MarshalObject();
                Assert.IsFalse(RemotingServices.IsObjectOutOfAppDomain(objMarshal), "#A18");
                Assert.IsFalse(RemotingServices.IsObjectOutOfContext(objMarshal), "#A19");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
        //Should have no refresh issues
        public override void LoadObject(ref object obj)
        {
            if (this.url.Length < 1)
            {
                throw new NPersistException("You must specify an url to your NPersist Web Service in your WebServiceRemotingEngine!");
            }
            RemotingService rs       = new RemotingService(this.Context, url);
            IClassMap       classMap = Context.DomainMap.MustGetClassMap(obj.GetType());
            string          id       = Context.ObjectManager.GetObjectIdentity(obj);

            bool doUseCompression = this.useCompression;

            if (this.compressor == null)
            {
                doUseCompression = false;
            }

            string result = rs.LoadObject(classMap.GetName(), id, this.domainKey, doUseCompression);

            if (useCompression && this.compressor != null)
            {
                result = this.compressor.Decompress(result);
            }

            MarshalObject          mo          = (MarshalObject)Formatter.Deserialize(result, typeof(MarshalObject));
            IMarshalingTransformer transformer = new MarshalingTransformer(Context);

            Context.IdentityMap.RegisterLoadedObject(obj);
            transformer.ToObject(mo, ref obj);
        }
        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);
            }
        }
Exemplo n.º 4
0
        public void ApplicationNameTest()
        {
            var port = NetworkHelpers.FindFreePort();

            RemotingConfiguration.ApplicationName = "app";
            TcpChannel chn = new TcpChannel(port);

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

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

                Assert.IsTrue(RemotingServices.IsTransparentProxy(objRem), "#AN1");
                Assert.IsTrue(RemotingServices.IsTransparentProxy(objRem2), "#AN2");

                Assert.IsNotNull(RemotingServices.GetServerTypeForUri("obj3.rem"), "#AN3");
                Assert.IsNotNull(RemotingServices.GetServerTypeForUri("/app/obj3.rem"), "#AN4");
                Assert.IsNull(RemotingServices.GetServerTypeForUri("//app/obj3.rem"), "#AN5");
                Assert.IsNull(RemotingServices.GetServerTypeForUri("app/obj3.rem"), "#AN6");
                Assert.IsNull(RemotingServices.GetServerTypeForUri("/whatever/obj3.rem"), "#AN7");
                Assert.IsNotNull(RemotingServices.GetServerTypeForUri("/obj3.rem"), "#AN8");
                Assert.IsNull(RemotingServices.GetServerTypeForUri("//obj3.rem"), "#AN9");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Exemplo n.º 5
0
        public void GetRealProxy()
        {
            TcpChannel chn = null;

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

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);

                MyProxy       proxy  = new  MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1241/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));
                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                RealProxy rp = RemotingServices.GetRealProxy(objRem);

                Assert.IsTrue(rp != null, "#A12");
                Assert.AreEqual("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString(), "#A13");
            }
            finally
            {
                if (chn != null)
                {
                    ChannelServices.UnregisterChannel(chn);
                }
            }
        }
Exemplo n.º 6
0
        public void ApplicationNameTest()
        {
            RemotingConfiguration.ApplicationName = "app";
            TcpChannel chn = new TcpChannel(1246);

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

                MarshalObject objRem  = (MarshalObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1246/app/obj3.rem");
                MarshalObject objRem2 = (MarshalObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1246/obj3.rem");

                Assert("#AN1", RemotingServices.IsTransparentProxy(objRem));
                Assert("#AN2", RemotingServices.IsTransparentProxy(objRem2));

                AssertNotNull("#AN3", RemotingServices.GetServerTypeForUri("obj3.rem"));
                AssertNotNull("#AN4", RemotingServices.GetServerTypeForUri("/app/obj3.rem"));
                AssertNull("#AN5", RemotingServices.GetServerTypeForUri("//app/obj3.rem"));
                AssertNull("#AN6", RemotingServices.GetServerTypeForUri("app/obj3.rem"));
                AssertNull("#AN7", RemotingServices.GetServerTypeForUri("/whatever/obj3.rem"));
                AssertNotNull("#AN8", RemotingServices.GetServerTypeForUri("/obj3.rem"));
                AssertNull("#AN9", RemotingServices.GetServerTypeForUri("//obj3.rem"));
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public void Marshal1()
        {
            MarshalObject objMarshal = NewMarshalObject();
            ObjRef        objRef     = RemotingServices.Marshal(objMarshal);

            Assert.IsTrue(objRef.URI != null, "#A01");

            MarshalObject objRem = (MarshalObject)RemotingServices.Unmarshal(objRef);

            Assert.AreEqual(objMarshal.Id, objRem.Id, "#A02");

            objRem.Id = 2;
            Assert.AreEqual(objMarshal.Id, objRem.Id, "#A03");

            // TODO: uncomment when RemotingServices.Disconnect is implemented
            //RemotingServices.Disconnect(objMarshal);

            objMarshal = NewMarshalObject();

            objRef = RemotingServices.Marshal(objMarshal, objMarshal.Uri);

            Assert.IsTrue(objRef.URI.EndsWith(objMarshal.Uri), "#A04");
            // TODO: uncomment when RemotingServices.Disconnect is implemented
            //RemotingServices.Disconnect(objMarshal);
        }
Exemplo n.º 9
0
        public void MarshalThrowException()
        {
            MarshalObject objMarshal = NewMarshalObject();

            IDictionary props = new Hashtable();

            props["name"] = objMarshal.Uri;
            props["port"] = 1237;
            TcpChannel chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);

            RemotingServices.Marshal(objMarshal, objMarshal.Uri);

            MarshalObject objRem = (MarshalObject)RemotingServices.Connect(typeof(MarshalObject), "tcp://localhost:1237/" + objMarshal.Uri);

            // This line sould throw a RemotingException
            // It is forbidden to export an object which is not
            // a real object
            try
            {
                RemotingServices.Marshal(objRem, objMarshal.Uri);
            }
            catch (Exception e)
            {
                ChannelServices.UnregisterChannel(chn);

                // TODO: uncomment when RemotingServices.Disconnect is implemented
                //RemotingServices.Disconnect(objMarshal);

                throw e;
            }
        }
Exemplo n.º 10
0
        public void GetServeurTypeForUri()
        {
            TcpChannel chn  = null;
            Type       type = typeof(MarshalObject);

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

                MarshalObject objRem = NewMarshalObject();
                RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);
                RemotingServices.Marshal(objRem);

                Type typeRem = RemotingServices.GetServerTypeForUri(RemotingServices.GetObjectUri(objRem));
                Assert.AreEqual(type, typeRem, "#A15");
            }
            finally
            {
                if (chn != null)
                {
                    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);
            }
        }
Exemplo n.º 12
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);
                }
            }
        }
Exemplo n.º 13
0
        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);
                }
            }
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
0
        public void IsObjectOutOf()
        {
            TcpChannel chn = null;

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

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MarshalObject.rem", WellKnownObjectMode.Singleton);

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

                Assert.IsTrue(RemotingServices.IsObjectOutOfAppDomain(objRem), "#A16");
                Assert.IsTrue(RemotingServices.IsObjectOutOfContext(objRem), "#A17");

                MarshalObject objMarshal = new MarshalObject();
                Assert.IsTrue(!RemotingServices.IsObjectOutOfAppDomain(objMarshal), "#A18");
                Assert.IsTrue(!RemotingServices.IsObjectOutOfContext(objMarshal), "#A19");
            }
            finally
            {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Exemplo n.º 16
0
        public void MarshalThrowException()
        {
            var           port       = NetworkHelpers.FindFreePort();
            MarshalObject objMarshal = NewMarshalObject();

            IDictionary props = new Hashtable();

            props ["name"] = objMarshal.Uri;
            props ["port"] = port;
            TcpChannel chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);

            try {
                RemotingServices.Marshal(objMarshal, objMarshal.Uri);
                MarshalObject objRem = (MarshalObject)RemotingServices.Connect(typeof(MarshalObject), $"tcp://localhost:{port}/" + objMarshal.Uri);
                // This line should throw a RemotingException
                // It is forbidden to export an object which is not
                // a real object
                try {
                    RemotingServices.Marshal(objRem, objMarshal.Uri);
                    Assert.Fail("#1");
                } catch (RemotingException e) {
                }
            } finally {
                ChannelServices.UnregisterChannel(chn);

                // TODO: uncomment when RemotingServices.Disconnect is implemented
                //RemotingServices.Disconnect(objMarshal);
            }
        }
Exemplo n.º 17
0
        private MarshalObject ToMarshalObject(XmlNode xmlObject)
        {
            MarshalObject mo = new MarshalObject();
            XmlNodeList   xmlNodeList;

            if (!(xmlObject.Attributes["type"] == null))
            {
                mo.Type = xmlObject.Attributes["type"].Value;
            }
            if (!(xmlObject.Attributes["temp-id"] == null))
            {
                mo.TempId = xmlObject.Attributes["temp-id"].Value;
            }
            xmlNodeList = xmlObject.SelectNodes("property");
            foreach (XmlNode xmlProp in xmlNodeList)
            {
                mo.Properties.Add(ToMarshalProperty(xmlProp));
            }
            xmlNodeList = xmlObject.SelectNodes("reference");
            foreach (XmlNode xmlProp in xmlNodeList)
            {
                mo.References.Add(ToMarshalReference(xmlProp));
            }
            return(mo);
        }
Exemplo n.º 18
0
        public XmlNode SerializeToXmlNode(XmlDocument xmlDoc, MarshalObject marshalObject)
        {
            XmlNode      xml = xmlDoc.CreateElement("object");
            XmlAttribute xmlAttr;

            xmlAttr       = xmlDoc.CreateAttribute("type");
            xmlAttr.Value = marshalObject.Type;
            xml.Attributes.Append(xmlAttr);

            xmlAttr       = xmlDoc.CreateAttribute("temp-id");
            xmlAttr.Value = marshalObject.TempId;
            xml.Attributes.Append(xmlAttr);

            foreach (MarshalProperty mp in marshalObject.Properties)
            {
                xml.AppendChild(SerializeToXmlNode(xmlDoc, mp));
            }

            foreach (MarshalReference mr in marshalObject.References)
            {
                xml.AppendChild(SerializeToXmlNode(xmlDoc, mr));
            }

            return(xml);
        }
Exemplo n.º 19
0
        public object LoadObject(string type, object identity, string domainKey)
        {
//			if (useCompression &&  this.compressor != null)
//			{
//				type = this.compressor.Decompress(type);
//				identity = this.compressor.Decompress((string) identity);
//				domainKey = this.compressor.Decompress(domainKey);
//			}

            IContext  ctx      = contextFactory.GetContext(domainKey);
            IClassMap classMap = ctx.DomainMap.MustGetClassMap(type);
            Type      realType = ctx.AssemblyManager.MustGetTypeFromClassMap(classMap);
            object    obj      = ctx.GetObjectById(identity, realType);
            IMarshalingTransformer transformer = new MarshalingTransformer(ctx);
            MarshalObject          mo          = transformer.FromObject(obj);
            object serialized = formater.Serialize(mo);

            ctx.Dispose();

            if (useCompression && this.compressor != null)
            {
                return(this.compressor.Compress((string)serialized));
            }
            else
            {
                return(serialized);
            }
        }
Exemplo n.º 20
0
        // Helper function that create a new
        // MarshalObject with an unique ID
        private static MarshalObject NewMarshalObject()
        {
            string        uri        = "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject" + MarshalObjectId.ToString();
            MarshalObject objMarshal = new MarshalObject(MarshalObjectId, uri);

            MarshalObjectId++;

            return(objMarshal);
        }
Exemplo n.º 21
0
        public void GetObjectUri()
        {
            MarshalObject objMarshal = NewMarshalObject();

            Assert("#A06", RemotingServices.GetObjectUri(objMarshal) == null);

            RemotingServices.Marshal(objMarshal);

            Assert("#A07", RemotingServices.GetObjectUri(objMarshal) != null);
            // TODO: uncomment when RemotingServices.Disconnect is implemented
            //RemotingServices.Disconnect(objMarshal);
        }
Exemplo n.º 22
0
        public void GetObjectUri()
        {
            MarshalObject objMarshal = NewMarshalObject();

            Assert.IsNull(RemotingServices.GetObjectUri(objMarshal), "#A06");

            RemotingServices.Marshal(objMarshal);

            Assert.IsNotNull(RemotingServices.GetObjectUri(objMarshal), "#A07");
            // TODO: uncomment when RemotingServices.Disconnect is implemented
            //RemotingServices.Disconnect(objMarshal);
        }
Exemplo n.º 23
0
        public void GetObjectUri()
        {
            MarshalObject objMarshal = NewMarshalObject();

            Assert.IsTrue(RemotingServices.GetObjectUri(objMarshal) == null, "#A06");

            ObjRef objRef = RemotingServices.Marshal(objMarshal);

            Assert.IsTrue(RemotingServices.GetObjectUri(objMarshal) != null, "#A07");
            // TODO: uncomment when RemotingServices.Disconnect is implemented
            //RemotingServices.Disconnect(objMarshal);
        }
Exemplo n.º 24
0
        public void CreateObjRef()
        {
            MarshalObject objMarshal = new MarshalObject();

            RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal1");
            RemotingServices.Marshal(objMarshal);

            ObjRef objRef = objMarshal.CreateObjRef(typeof(MarshalObject));

            Assert.AreEqual(objRef.URI, RemotingServices.GetObjectUri(objMarshal), "#A01");

            // TODO: When implemented in the mono RemotingServices class
            //RemotingServices.Disconnect(objMarshal);
        }
Exemplo n.º 25
0
        public void LifetimeService()
        {
            MarshalObject objMarshal = new MarshalObject();

            RemotingServices.SetObjectUriForMarshal(objMarshal, "MarshalByRefObjectTest.objMarshal2");
            RemotingServices.Marshal(objMarshal);

            objMarshal.InitializeLifetimeService();
            ILease lease = (ILease)objMarshal.GetLifetimeService();

            Assert.AreEqual(lease.InitialLeaseTime, TimeSpan.FromSeconds(10), "#A02");

            // TODO: When implemented in the mono RemotingServices class
            //RemotingServices.Disconnect(objMarshal);
        }
Exemplo n.º 26
0
        public void SetObjectUriForMarshal()
        {
            TcpChannel chn = new TcpChannel(1242);

            ChannelServices.RegisterChannel(chn);
            try {
                MarshalObject objRem = NewMarshalObject();
                RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);
                RemotingServices.Marshal(objRem);

                objRem = (MarshalObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1242/" + objRem.Uri);
                Assert("#A14", objRem != null);
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Exemplo n.º 27
0
        public void SetObjectUriForMarshal()
        {
            var        port = NetworkHelpers.FindFreePort();
            TcpChannel chn  = new TcpChannel(port);

            ChannelServices.RegisterChannel(chn);
            try {
                MarshalObject objRem = NewMarshalObject();
                RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);
                RemotingServices.Marshal(objRem);

                objRem = (MarshalObject)Activator.GetObject(typeof(MarshalObject), $"tcp://localhost:{port}/" + objRem.Uri);
                Assert.IsNotNull(objRem, "#A14");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Exemplo n.º 28
0
        public void GetServeurTypeForUri()
        {
            var        port = NetworkHelpers.FindFreePort();
            TcpChannel chn  = new TcpChannel(port);
            Type       type = typeof(MarshalObject);

            ChannelServices.RegisterChannel(chn);
            try {
                MarshalObject objRem = NewMarshalObject();
                RemotingServices.SetObjectUriForMarshal(objRem, objRem.Uri);
                RemotingServices.Marshal(objRem);

                Type typeRem = RemotingServices.GetServerTypeForUri(RemotingServices.GetObjectUri(objRem));
                Assert.AreEqual(type, typeRem, "#A15");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Exemplo n.º 29
0
        [Test]         // TcpChannel (IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)
        public void Constructor3()
        {
            const string SERVICE_URI = "MarshalSvc";

            string []        urls;
            ChannelDataStore ds;
            TcpChannel       chn;

            MarshalObject marshal = new MarshalObject();

            var         port  = NetworkHelpers.FindFreePort();
            IDictionary props = new Hashtable();

            props ["name"]   = "marshal channel";
            props ["port"]   = port;
            props ["bindTo"] = IPAddress.Loopback.ToString();
            chn = new TcpChannel(props, null, null);

            ChannelServices.RegisterChannel(chn);

            Assert.AreEqual("marshal channel", chn.ChannelName, "#A1");
            urls = chn.GetUrlsForUri(SERVICE_URI);
            Assert.IsNotNull(urls, "#A2");
            Assert.AreEqual(1, urls.Length, "#A3");
            Assert.AreEqual($"tcp://{IPAddress.Loopback.ToString ()}:{port}/{SERVICE_URI}", urls [0], "#A6");
            ds = chn.ChannelData as ChannelDataStore;
            Assert.IsNotNull(ds, "#A4");
            Assert.AreEqual(1, ds.ChannelUris.Length, "#A5");
            Assert.AreEqual($"tcp://{IPAddress.Loopback.ToString ()}:{port}", ds.ChannelUris [0], "#A6");

            ChannelServices.UnregisterChannel(chn);

            chn = new TcpChannel((IDictionary)null, null, null);

            ChannelServices.RegisterChannel(chn);

            Assert.AreEqual("tcp", chn.ChannelName, "#B1");
            urls = chn.GetUrlsForUri(SERVICE_URI);
            Assert.IsNull(urls, "#B1");
            ds = chn.ChannelData as ChannelDataStore;
            Assert.IsNull(ds, "#B2");

            ChannelServices.UnregisterChannel(chn);
        }
Exemplo n.º 30
0
        public void GetRealProxy()
        {
            var        port = NetworkHelpers.FindFreePort();
            TcpChannel chn  = new TcpChannel(port);

            ChannelServices.RegisterChannel(chn);
            try {
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);

                MyProxy       proxy  = new MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), $"tcp://localhost:{port}/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));
                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                RealProxy rp = RemotingServices.GetRealProxy(objRem);

                Assert.IsNotNull(rp, "#A12");
                Assert.AreEqual("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString(), "#A13");
            } finally {
                ChannelServices.UnregisterChannel(chn);
            }
        }
Exemplo n.º 31
0
		[Test] // TcpChannel (IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)
		public void Constructor3 ()
		{
			const string SERVICE_URI = "MarshalSvc";
			string [] urls;
			ChannelDataStore ds;
			TcpChannel chn;

			MarshalObject marshal = new MarshalObject ();

			IDictionary props = new Hashtable ();
			props ["name"] = "marshal channel";
			props ["port"] = 1236;
			props ["bindTo"] = IPAddress.Loopback.ToString ();
			chn = new TcpChannel (props, null, null);

			ChannelServices.RegisterChannel (chn);

			Assert.AreEqual ("marshal channel", chn.ChannelName, "#A1");
			urls = chn.GetUrlsForUri (SERVICE_URI);
			Assert.IsNotNull (urls, "#A2");
			Assert.AreEqual (1, urls.Length, "#A3");
			Assert.AreEqual ("tcp://" + IPAddress.Loopback.ToString () + ":1236/" + SERVICE_URI, urls [0], "#A6");
			ds = chn.ChannelData as ChannelDataStore;
			Assert.IsNotNull (ds, "#A4");
			Assert.AreEqual (1, ds.ChannelUris.Length, "#A5");
			Assert.AreEqual ("tcp://" + IPAddress.Loopback.ToString () + ":1236", ds.ChannelUris [0], "#A6");

			ChannelServices.UnregisterChannel (chn);
			
			chn = new TcpChannel ((IDictionary) null, null, null);

			ChannelServices.RegisterChannel (chn);

			Assert.AreEqual ("tcp", chn.ChannelName, "#B1");
			urls = chn.GetUrlsForUri (SERVICE_URI);
			Assert.IsNull (urls, "#B1");
			ds = chn.ChannelData as ChannelDataStore;
			Assert.IsNull (ds, "#B2");

			ChannelServices.UnregisterChannel (chn);
		}