public bool Start()
        {
            Exception ex;

            this.m_service = MonitoringService.StartListening(this.m_healthTracker, out ex);
            return(ex == null);
        }
예제 #2
0
        public static MonitoringService StartListening(IDatabaseHealthTracker healthTracker, out Exception exception)
        {
            MonitoringService.Tracer.TraceDebug(0L, "Starting Monitoring WCF Service listener.");
            exception = null;
            MonitoringService monitoringService = null;

            try
            {
                monitoringService        = new MonitoringService(healthTracker);
                monitoringService.m_host = new ServiceHost(monitoringService, new Uri[]
                {
                    MonitoringService.baseAddress
                });
                NetTcpBinding netTcpBinding = new NetTcpBinding();
                netTcpBinding.PortSharingEnabled                  = true;
                netTcpBinding.MaxBufferPoolSize                   = 16777216L;
                netTcpBinding.MaxBufferSize                       = 16777216;
                netTcpBinding.MaxConnections                      = 100;
                netTcpBinding.MaxReceivedMessageSize              = 16777216L;
                netTcpBinding.ReaderQuotas.MaxDepth               = 128;
                netTcpBinding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
                netTcpBinding.ReaderQuotas.MaxBytesPerRead        = int.MaxValue;
                netTcpBinding.ReaderQuotas.MaxNameTableCharCount  = int.MaxValue;
                netTcpBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
                monitoringService.m_host.AddServiceEndpoint(typeof(IInternalMonitoringService), netTcpBinding, string.Empty);
                ServiceDebugBehavior serviceDebugBehavior = monitoringService.m_host.Description.Behaviors.Find <ServiceDebugBehavior>();
                if (serviceDebugBehavior != null)
                {
                    serviceDebugBehavior.IncludeExceptionDetailInFaults = true;
                }
                else
                {
                    monitoringService.m_host.Description.Behaviors.Add(new ServiceDebugBehavior
                    {
                        IncludeExceptionDetailInFaults = true
                    });
                }
                monitoringService.m_host.OpenTimeout = TimeSpan.FromSeconds(30.0);
                monitoringService.m_host.Open();
                return(monitoringService);
            }
            catch (CommunicationException ex)
            {
                exception = ex;
            }
            catch (ConfigurationException ex2)
            {
                exception = ex2;
            }
            catch (TimeoutException ex3)
            {
                exception = ex3;
            }
            catch (InvalidOperationException ex4)
            {
                exception = ex4;
            }
            if (exception != null)
            {
                MonitoringService.Tracer.TraceError <Exception>(0L, "StartListening() failed to register WCF Monitoring service with exception: {0}", exception);
                ReplayCrimsonEvents.MonitoringServiceFailedToRegister.LogPeriodic <string, string>(Environment.MachineName, DateTimeHelper.OneHour, exception.Message, exception.StackTrace);
            }
            if (monitoringService != null && monitoringService.m_host != null)
            {
                monitoringService.m_host.Abort();
            }
            return(null);
        }