Exemplo n.º 1
0
        /// <summary>
        /// Return the CAO proxy.
        /// </summary>
        /// <returns>the CAO proxy</returns>
        public object GetObject()
        {
            string url = serviceUrl.TrimEnd('/') + '/' + remoteTargetName;

            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("Accessing CAO object of type ICaoRemoteFactory object at url = [" + url + "]");
            }
            ICaoRemoteFactory remoteFactory = (ICaoRemoteFactory)Activator.GetObject(typeof(ICaoRemoteFactory), url);

            if (constructorArguments != null)
            {
                return(remoteFactory.GetObject(constructorArguments));
            }
            else
            {
                return(remoteFactory.GetObject());
            }
        }
        public void RegistersSimpleObject()
        {
            IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/caoLifetimeService.xml");

            ContextRegistry.RegisterContext(ctx);

            ICaoRemoteFactory caoFactory = Activator.GetObject(typeof(ICaoRemoteFactory), "tcp://localhost:8005/counter2") as ICaoRemoteFactory;

            Assert.IsNotNull(caoFactory, "Cao factory is null even though it has been registered.");

            MarshalByRefObject cao = caoFactory.GetObject() as MarshalByRefObject;

            Assert.IsNotNull(cao);
        }
        public void RegistersWithLifetimeService()
        {
            IApplicationContext ctx = new XmlApplicationContext("assembly://Spring.Services.Tests/Spring.Data.Spring.Remoting/caoLifetimeService.xml");

            ContextRegistry.RegisterContext(ctx);

            ICaoRemoteFactory caoFactory = Activator.GetObject(typeof(ICaoRemoteFactory), "tcp://localhost:8005/counter2") as ICaoRemoteFactory;

            Assert.IsNotNull(caoFactory, "Cao factory is null even though it has been registered.");

            MarshalByRefObject cao = caoFactory.GetObject() as MarshalByRefObject;

            Assert.IsNotNull(cao);

            ILease lease = (ILease)cao.GetLifetimeService();

            Assert.AreEqual(TimeSpan.FromMilliseconds(10000), lease.InitialLeaseTime, "InitialLeaseTime");
            Assert.AreEqual(TimeSpan.FromMilliseconds(1000), lease.RenewOnCallTime, "RenewOnCallTime");
            Assert.AreEqual(TimeSpan.FromMilliseconds(100), lease.SponsorshipTimeout, "SponsorshipTimeout");
        }