Beispiel #1
0
        private static void DisposeAllService()
        {
            if (_functionServiceHost != null)
            {
                try
                {
                    _functionServiceHost.Close();
                    LogHelper.Log(LogLevel.Info, ">>> Discovery for Function service stopped ....");
                    _functionServiceHost = null;
                }
                catch (System.ServiceModel.CommunicationObjectFaultedException exc)
                {
                    LogHelper.LogException(">>> Cannot proper close Discovery for Function service!", exc);
                }
            }

            if (_mCServiceHost != null)
            {
                try
                {
                    _mCServiceHost.Close();
                    LogHelper.Log(LogLevel.Info, ">>> Discovery for Monitor and control service stopped ....");
                    _mCServiceHost = null;
                }
                catch (System.ServiceModel.CommunicationObjectFaultedException exc)
                {
                    LogHelper.LogException(">>> Cannot proper close Discovery for Monitor and control service!", exc);
                }
            }

            if (_configurationServiceHost != null)
            {
                try
                {
                    _configurationServiceHost.Close();
                    LogHelper.Log(LogLevel.Info, ">>> Discovery for Configuration service stopped ....");
                    _configurationServiceHost = null;
                }
                catch (System.ServiceModel.CommunicationObjectFaultedException exc)
                {
                    LogHelper.LogException(">>> Cannot proper close Discovery for Configuration service!", exc);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// To set permission, call with admin rights:
        ///    netsh http add urlacl url=http://+:7400/ConfigurationService user=WW002\imfeldc
        ///    netsh http add urlacl url=http://+:7400/FunctionService user=WW002\imfeldc
        ///    netsh http add urlacl url=http://+:7400/MonitorAndControlService user=WW002\imfeldc
        /// More details see https://msdn.microsoft.com/library/ms733768.aspx
        /// </summary>
        private static void HostAllServices()
        {
            /*
             * // URI used to connect within local LAN networks
             * ServiceHost configurationServiceHost = new ServiceHost(_configurationService,
             *  new Uri(NetworkHelper.buildEndpointAddress("http://localhost:8080/ConfigurationService")));
             * ServiceHostMc mCServiceHost = new ServiceHostMc(
             *  typeof(NuvoControl.Server.MonitorAndControlService.MonitorAndControlService), _zoneServer,
             *  new Uri(NetworkHelper.buildEndpointAddress("http://localhost:8080/MonitorAndControlService")));
             * ServiceHostFunction functionServiceHost = new ServiceHostFunction(
             *  typeof(NuvoControl.Server.FunctionService.FunctionService), _zoneServer, _configurationService.SystemConfiguration.Functions,
             *  new Uri(NetworkHelper.buildEndpointAddress("http://localhost:8080/FunctionService")));
             */

            /*
             * // URI used to connect via internet
             * // NOTE: This requires that dyndns service is running and up-to-date. The imfeldc.dyndns.org address will point to the access point, which itself is configured to forward
             * // and request to the virtual machine imfihpavm.
             * _configurationServiceHost = new ServiceHost(_configurationService,
             *  new Uri(NetworkHelper.buildEndpointAddress("http://imfeldc.dyndns.org:8080/ConfigurationService")));
             * _mCServiceHost = new ServiceHostMc(
             *  typeof(NuvoControl.Server.MonitorAndControlService.MonitorAndControlService), _zoneServer,
             *  new Uri(NetworkHelper.buildEndpointAddress("http://imfeldc.dyndns.org:8080/MonitorAndControlService")));
             * _functionServiceHost = new ServiceHostFunction(
             *  typeof(NuvoControl.Server.FunctionService.FunctionService), _zoneServer, _configurationService.SystemConfiguration.Functions,
             *  new Uri(NetworkHelper.buildEndpointAddress("http://imfeldc.dyndns.org:8080/FunctionService")));
             */


            string hostname    = System.Environment.MachineName;
            int    portnumber  = 7400;
            var    baseAddress = new UriBuilder("http", hostname, portnumber, "ConfigurationService");

            _configurationServiceHost = new ServiceHost(
                /*typeof(NuvoControl.Server.ConfigurationService.ConfigurationService)*/ _configurationService, new UriBuilder("http", hostname, portnumber, "ConfigurationService").Uri);
            _mCServiceHost = new ServiceHostMc(
                typeof(NuvoControl.Server.MonitorAndControlService.MonitorAndControlService), _zoneServer,
                new UriBuilder("http", hostname, portnumber, "MonitorAndControlService").Uri);
            _functionServiceHost = new ServiceHostFunction(
                typeof(NuvoControl.Server.FunctionService.FunctionService), _zoneServer, _configurationService.SystemConfiguration.Functions,
                new UriBuilder("http", hostname, portnumber, "FunctionService").Uri);


            try
            {
                // make the service discoverable by adding the discovery behavior
                _configurationServiceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
                // add the discovery endpoint that specifies where to publish the services
                _configurationServiceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());
                LogHelper.Log(LogLevel.All, ">>> Discovery for Configuration service started ....");
                try
                {
                    _configurationServiceHost.Open();
                    LogHelper.Log(LogLevel.Info, ">>> Configuration service is running.");
                    LogHelper.Log(LogLevel.Debug, String.Format(">>> URI: {0}", _configurationServiceHost.BaseAddresses[0].AbsoluteUri));
                }
                catch (System.ServiceModel.AddressAccessDeniedException exc)
                {
                    // see comment above, to set correct required permissions
                    LogHelper.LogException(">>> Cannot open Discovery for Configuration service!", exc);
                }

                // make the service discoverable by adding the discovery behavior
                _mCServiceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
                // add the discovery endpoint that specifies where to publish the services
                _mCServiceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());
                LogHelper.Log(LogLevel.All, ">>> Discovery for Monitor and control service started ....");
                try
                {
                    _mCServiceHost.Open();
                    LogHelper.Log(LogLevel.Info, ">>> Monitor and control service is running.");
                    LogHelper.Log(LogLevel.Debug, String.Format(">>> URI: {0}", _mCServiceHost.BaseAddresses[0].AbsoluteUri));
                }
                catch (System.ServiceModel.AddressAccessDeniedException exc)
                {
                    // see comment above, to set correct required permissions
                    LogHelper.LogException(">>> Cannot open Discovery for Monitor and control service!", exc);
                }

                // make the service discoverable by adding the discovery behavior
                _functionServiceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
                // add the discovery endpoint that specifies where to publish the services
                _functionServiceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());
                LogHelper.Log(LogLevel.All, ">>> Discovery for Function service started ....");
                try
                {
                    _functionServiceHost.Open();
                    LogHelper.Log(LogLevel.Info, ">>> Function service is running.");
                    LogHelper.Log(LogLevel.Debug, String.Format(">>> URI: {0}", _functionServiceHost.BaseAddresses[0].AbsoluteUri));
                }
                catch (System.ServiceModel.AddressAccessDeniedException exc)
                {
                    // see comment above, to set correct required permissions
                    LogHelper.LogException(">>> Cannot open Discovery for Function service!", exc);
                }
            }
            catch (Exception exc)
            {
                LogHelper.LogException("Failed to start services.", exc);
                LogHelper.Log(LogLevel.All, ">>> Press <Enter> to close the console.");
                Console.ReadLine();
            }
        }