Ejemplo n.º 1
0
        private bool disposedValue = false; // To detect redundant calls


        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    if (this._hostsSlot != null)
                    {
                        foreach (var host in this._hostsSlot.Hosts)
                        {
                            host.Close();
                        }
                        this._hostsSlot = null;
                    }
                    if (this._hostFactory != null)
                    {
                        this._hostFactory = null;
                        this.Logger.Info("AppServer: The tech service host has been closed");
                    }
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            //var helloServiceModel = new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/hello"));//.AddExtensions(new GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler)));

            var throttlingBehavior = new ServiceThrottlingBehavior {
                MaxConcurrentCalls = Environment.ProcessorCount * 16, MaxConcurrentSessions = (Environment.ProcessorCount * 16) + (Environment.ProcessorCount * 100), MaxConcurrentInstances = Environment.ProcessorCount * 100
            };


            var helloServiceModel = new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/hello")).AddExtensions(new GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler)), throttlingBehavior);

            helloServiceModel.OnCreated(host => {
                host.Authorization.PrincipalPermissionMode       = PrincipalPermissionMode.Custom;
                host.Authorization.ExternalAuthorizationPolicies = new System.Collections.ObjectModel.ReadOnlyCollection <System.IdentityModel.Policy.IAuthorizationPolicy>(new List <IAuthorizationPolicy>()
                {
                    new CustomAuthorizationPolicy()
                });


                //var od = host.Description.Endpoints[0].Contract.Operations.Find("Handle");
                //var serializerBehavior = od.Behaviors.Find<DataContractSerializerOperationBehavior>();

                //if (serializerBehavior == null)
                //{
                //    serializerBehavior = new DataContractSerializerOperationBehavior(od);
                //    od.Behaviors.Add(serializerBehavior);
                //}

                //serializerBehavior.DataContractResolver = new SharedTypeResolver();
            });



            var windsorContainer = new WindsorContainer().AddFacility <WcfFacility>();

            windsorContainer.Register(
                Component.For <LoggingCallContextInitializer>(),
                Component.For <LoggingBehavior>(),
                Component.For <IConsoleService>().ImplementedBy <ConsoleService>().AsWcfService(new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/console"))),
                Component.For <IRequestHandlerService>().ImplementedBy <RequestHandlerService>().AsWcfService(new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/requestHandler"))),
                Component.For <IHelloService>().ImplementedBy <HelloService>().AsWcfService(helloServiceModel)

                );

            var hostFactory        = new DefaultServiceHostFactory(windsorContainer.Kernel);
            var helloHost          = hostFactory.CreateServiceHost <IHelloService>();
            var consoleHost        = hostFactory.CreateServiceHost <IConsoleService>();
            var requestHandlerHost = hostFactory.CreateServiceHost <IRequestHandlerService>();

            try
            {
                Console.ReadLine();
            }
            finally
            {
                helloHost.Close();
                consoleHost.Close();
                requestHandlerHost.Close();
            }
        }
        static void Main(string[] args)
        {
            ServiceHost svcHost = null;

            try
            {
                var container = new WindsorContainer();

                container.AddFacility <WcfFacility>().Install(FromAssembly.Named("SystemManagament"));
                container.Register(Component.For <IWorkstationMonitorService>().ImplementedBy <WorkstationMonitorService>());

                var assemblyQualifiedName = typeof(IWorkstationMonitorService).AssemblyQualifiedName;
                //var factory = new DefaultServiceHostFactory(container.Kernel);
                var serviceHost = new DefaultServiceHostFactory().CreateServiceHost(assemblyQualifiedName, new Uri[0]);
                //var serviceHost = new DefaultServiceHostFactory()
                //    .CreateServiceHost(assemblyQualifiedName, new[] { new Uri("net.tcp://localhost:8000/") });
                serviceHost.Open();

                Console.WriteLine("\n\nService is running.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Service can not be started \n\nError Message: [{ex.Message}]");
            }
            finally
            {
                Console.WriteLine("\nPress any key to close the Service");
                Console.ReadKey();
                svcHost.Close();
                svcHost = null;
            }
        }
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Component.For <I_S_ShortProductName_S_Manager>().ImplementedBy <_S_ShortProductName_S_Manager>());
            container.Register(Component.For <I_S_ShortProductName_S_WindowsService2>().ImplementedBy <_S_ShortProductName_S_WindowsService2>());
            var defaultServiceHostFactory = new DefaultServiceHostFactory(container.Kernel);

            container.Register(Component.For <DefaultServiceHostFactory>().Instance(defaultServiceHostFactory));
        }
Ejemplo n.º 5
0
        public TechServicesHost(ITechServiceHostsSlot hostsSlot, IWindsorContainer container, ILogger logger) : base(logger)
        {
            this._hostsSlot   = hostsSlot;
            this._container   = container;
            this._hostFactory = new DefaultServiceHostFactory(this._container.Kernel);

            foreach (var host in this._hostsSlot.Hosts)
            {
                host.Install(container);
            }
        }
Ejemplo n.º 6
0
		public void CanCreateServiceByName()
		{
			IWindsorContainer windsorContainer = new WindsorContainer()
				.AddComponent("operations", typeof(IOperations), typeof(Operations))
				.AddComponent<IServiceHostBuilder<DefaultServiceModel>, DefaultServiceHostBuilder>();

			DefaultServiceHostFactory factory = new DefaultServiceHostFactory(windsorContainer.Kernel);
			ServiceHostBase serviceHost = factory.CreateServiceHost("operations", 
				new Uri[] {new Uri("http://localhost/Foo.svc")});
			Assert.IsNotNull(serviceHost);
		}
Ejemplo n.º 7
0
        private void CreateServiceHost <T>(ref ServiceHostBase host, string message)
        {
            host = new DefaultServiceHostFactory(container.Kernel)
                   .CreateServiceHost(typeof(T).AssemblyQualifiedName, new Uri[0]);

            // Hook on to the service host faulted events.
            host.Faulted += new WeakEventHandler <EventArgs>(OnServiceFaulted).Handler;

            // Open the ServiceHostBase to create listeners and start listening for messages.
            host.Open();
            logger.Info(string.Format("SachaBarber CQRS Demo {0} Started", message));
        }
		public void CanCreateServiceByName()
		{
			IWindsorContainer windsorContainer = new WindsorContainer()
				.Register(Component.For<IOperations>().ImplementedBy<Operations>().Named("operations"),
						  Component.For<IServiceHostBuilder<DefaultServiceModel>>().ImplementedBy<DefaultServiceHostBuilder>()
						  );

			DefaultServiceHostFactory factory = new DefaultServiceHostFactory(windsorContainer.Kernel);
			ServiceHostBase serviceHost = factory.CreateServiceHost("operations", 
				new Uri[] {new Uri("http://localhost/Foo.svc")});
			Assert.IsNotNull(serviceHost);
		}
Ejemplo n.º 9
0
        public void CanCreateServiceByName()
        {
            IWindsorContainer windsorContainer = new WindsorContainer()
                                                 .Register(Component.For <IOperations>().ImplementedBy <Operations>().Named("operations"),
                                                           Component.For <IServiceHostBuilder <DefaultServiceModel> >().ImplementedBy <DefaultServiceHostBuilder>()
                                                           );

            DefaultServiceHostFactory factory     = new DefaultServiceHostFactory(windsorContainer.Kernel);
            ServiceHostBase           serviceHost = factory.CreateServiceHost("operations",
                                                                              new Uri[] { new Uri("http://localhost/Foo.svc") });

            Assert.IsNotNull(serviceHost);
        }
Ejemplo n.º 10
0
        public static void Main()
        {
            //var helloServiceModel = new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/hello"));//.AddExtensions(new GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler)));

            var throttlingBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = Environment.ProcessorCount * 16, MaxConcurrentSessions = (Environment.ProcessorCount * 16) + (Environment.ProcessorCount * 100), MaxConcurrentInstances = Environment.ProcessorCount * 100 };

            var helloServiceModel = new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/hello")).AddExtensions(new GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler)), throttlingBehavior );

            helloServiceModel.OnCreated(host => {
                host.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.Custom;
                host.Authorization.ExternalAuthorizationPolicies = new System.Collections.ObjectModel.ReadOnlyCollection<System.IdentityModel.Policy.IAuthorizationPolicy>(new List<IAuthorizationPolicy>() { new CustomAuthorizationPolicy() });

                //var od = host.Description.Endpoints[0].Contract.Operations.Find("Handle");
                //var serializerBehavior = od.Behaviors.Find<DataContractSerializerOperationBehavior>();

                //if (serializerBehavior == null)
                //{
                //    serializerBehavior = new DataContractSerializerOperationBehavior(od);
                //    od.Behaviors.Add(serializerBehavior);
                //}

                //serializerBehavior.DataContractResolver = new SharedTypeResolver();
            });

            var windsorContainer = new WindsorContainer().AddFacility<WcfFacility>();
            windsorContainer.Register(
                Component.For<LoggingCallContextInitializer>(),
                Component.For<LoggingBehavior>(),
                Component.For<IConsoleService>().ImplementedBy<ConsoleService>().AsWcfService(new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/console"))),
                Component.For<IRequestHandlerService>().ImplementedBy<RequestHandlerService>().AsWcfService(new DefaultServiceModel(WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://localhost:9101/requestHandler"))),
                Component.For<IHelloService>().ImplementedBy<HelloService>().AsWcfService(helloServiceModel)

                );

            var hostFactory = new DefaultServiceHostFactory(windsorContainer.Kernel);
            var helloHost = hostFactory.CreateServiceHost<IHelloService>();
            var consoleHost = hostFactory.CreateServiceHost<IConsoleService>();
            var requestHandlerHost = hostFactory.CreateServiceHost<IRequestHandlerService>();

            try
            {
                Console.ReadLine();
            }
            finally
            {
                helloHost.Close();
                consoleHost.Close();
                requestHandlerHost.Close();
            }
        }
Ejemplo n.º 11
0
 private ServiceHost createServiceHost()
 {
     WindsorContainer container = new WindsorContainer();
     container.AddFacility<WcfFacility>();
     container.Register(
         Component.For<WebService>().
         DependsOn(Dependency.OnValue("contentSubPath", contentPath))
         .DependsOn(Dependency.OnValue("errorPageTemplatePath", errorPagePath))
         );
     DefaultServiceHostFactory castleWindsorFactory =
         new DefaultServiceHostFactory(container.Kernel);
     var windsorServiceHost = (ServiceHost)castleWindsorFactory.
         CreateServiceHost(typeof(WebService).AssemblyQualifiedName, new Uri[] { });
     return windsorServiceHost;
 }
Ejemplo n.º 12
0
        void IAppServerComponent.Install(IWindsorContainer container, IAppServerContext serverContext)
        {
            this._logger = container.Resolve <ILogger>();

            container.AddFacility <WcfFacility>();

            container.Register(
                Component.For <TContract>()
                .ImplementedBy <TImplementedBy>()
                .LifestylePerWcfOperation()
                );

            this._hostFactory = new DefaultServiceHostFactory(container.Kernel);
            this._serviceHost = this._hostFactory.CreateServiceHost(typeof(TContract).AssemblyQualifiedName, new Uri[0]);
        }
Ejemplo n.º 13
0
        private ServiceHost createServiceHost()
        {
            WindsorContainer container = new WindsorContainer();

            container.AddFacility <WcfFacility>();
            container.Register(
                Component.For <WebService>().
                DependsOn(Dependency.OnValue("contentSubPath", contentPath))
                .DependsOn(Dependency.OnValue("errorPageTemplatePath", errorPagePath))
                );
            DefaultServiceHostFactory castleWindsorFactory =
                new DefaultServiceHostFactory(container.Kernel);
            var windsorServiceHost = (ServiceHost)castleWindsorFactory.
                                     CreateServiceHost(typeof(WebService).AssemblyQualifiedName, new Uri[] { });

            return(windsorServiceHost);
        }
Ejemplo n.º 14
0
        private ServiceHostBase CreateAndOpenWCFHost(string constructorString)
        {
            ServiceHostBase serviceHost     = new DefaultServiceHostFactory().CreateServiceHost(constructorString, new Uri[0]);
            ServiceEndpoint serviceEndpoint = serviceHost.Description.Endpoints.SingleOrDefault(x => x.Binding is BasicHttpBinding);

            if (!serviceHost.Description.Behaviors.Any(x => x is ServiceMetadataBehavior) && serviceEndpoint != null)
            {
                string uriString = serviceEndpoint.Address.Uri.ToString().Replace("localhost", Environment.MachineName);

                var metadataBehavior = new ServiceMetadataBehavior
                {
                    HttpGetEnabled = true,
                    HttpGetUrl     = new Uri(uriString)
                };
                serviceHost.Description.Behaviors.Add(metadataBehavior);
            }
            serviceHost.Open();
            return(serviceHost);
        }
Ejemplo n.º 15
0
        private ServiceHostBase CreateAndOpenWCFHost(string constructorString)
        {
            ServiceHostBase serviceHost = new DefaultServiceHostFactory().CreateServiceHost(constructorString, new Uri[0]);
            ServiceEndpoint serviceEndpoint = serviceHost.Description.Endpoints.SingleOrDefault(x => x.Binding is BasicHttpBinding);

            if (!serviceHost.Description.Behaviors.Any(x => x is ServiceMetadataBehavior) && serviceEndpoint != null)
            {
                string uriString = serviceEndpoint.Address.Uri.ToString().Replace("localhost", Environment.MachineName);

                var metadataBehavior = new ServiceMetadataBehavior
                    {
                        HttpGetEnabled = true,
                        HttpGetUrl = new Uri(uriString)
                    };
                serviceHost.Description.Behaviors.Add(metadataBehavior);
            }
            serviceHost.Open();
            return serviceHost;
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            var container = new WindsorContainer();
              IoCInitializer.Initialize(container);

              try
              {
            Initializer.Init();
              }
              catch (Exception e)
              {
            Console.WriteLine(e);
              }

              var factory = new DefaultServiceHostFactory(container.Kernel);
              using (var serviceHost = factory.CreateServiceHost(typeof(IService1).AssemblyQualifiedName, new Uri[0]))
              {
            serviceHost.Open();

            Console.WriteLine("Press return to stop the service ...");
            Console.ReadLine();
              }
        }
Ejemplo n.º 17
0
 private ServiceHostBase CreateAndOpenWCFHost(string constructorString)
 {
     ServiceHostBase serviceHost = new DefaultServiceHostFactory().CreateServiceHost(constructorString, new Uri[0]);
     serviceHost.Open();
     return serviceHost;
 }
		public void CanCreateWindsorHostFactory()
		{
			DefaultServiceHostFactory factory = new DefaultServiceHostFactory(new WindsorContainer().Kernel);
			Assert.IsNotNull(factory);
		}
Ejemplo n.º 19
0
 public _S_ShortProductName_S_WindowsService2(DefaultServiceHostFactory defaultServiceHostFactory, ILog logger)
 {
     _defaultServiceHostFactory = defaultServiceHostFactory;
     _logger = logger;
 }
Ejemplo n.º 20
0
        public void CanCreateWindsorHostFactory()
        {
            DefaultServiceHostFactory factory = new DefaultServiceHostFactory(new WindsorContainer().Kernel);

            Assert.IsNotNull(factory);
        }
Ejemplo n.º 21
0
 public static ServiceHostBase CreateServiceHost <TService>(this DefaultServiceHostFactory factory)
 {
     return(factory.CreateServiceHost(typeof(TService).AssemblyQualifiedName, new Uri[0]));
 }