Ejemplo n.º 1
0
        private static ServiceHost CreateServiceHost(DataService singletonServiceInstance, Uri[] baseAddresses, int maxConcurrency, int maxPending)
        {
            if (maxConcurrency < 1 || maxConcurrency > 10000)
            {
                throw new ArgumentOutOfRangeException("maxConcurrency", maxConcurrency, "Invalid value");
            }

            var serviceHost = new WebServiceHost(singletonServiceInstance, baseAddresses);
            var serviceThrottlingBehavior = new ServiceThrottlingBehavior
                {
                    MaxConcurrentInstances = maxConcurrency,
                    MaxConcurrentCalls = maxConcurrency,
                    MaxConcurrentSessions = maxConcurrency
                };
            serviceHost.Description.Behaviors.Add(serviceThrottlingBehavior);

            serviceHost.AddServiceEndpoint(typeof(IDataService), GetBinding(maxPending), String.Empty);
            return serviceHost;
        }
Ejemplo n.º 2
0
        public void Start(IHostingService host)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            m_tracer = host.GetTracer(GetType());
            m_host = host;
            m_instanceName = GetInstanceName();

            var tcpBaseAddress = GetTcpBaseAddress();
            var httpBaseAddress = GetHealthServiceBaseAddress();

            try
            {
                PerfCounters.Remove();
                PerfCounters.Install();
            }
            catch (Exception e)
            {
                m_tracer.Exception(e);
                throw;
            }

            var maxConcurrency = Environment.ProcessorCount * 16;
            var maxPending = Environment.ProcessorCount * 16;

            m_singletonServiceInstance = new DataService(
                m_host.GetTracer(typeof(DataService)), this, tcpBaseAddress.Authority + ", " + m_instanceName, maxConcurrency, null);

            var serviceHost = CreateServiceHost(m_singletonServiceInstance, new[] { tcpBaseAddress, httpBaseAddress }, maxConcurrency, maxPending);
            serviceHost.Open();
            m_serviceHost = serviceHost;

            if (m_tracer.IsInfoEnabled)
            {
                var builder = new StringBuilder(200);
                foreach (var ep in serviceHost.ChannelDispatchers)
                {
                    if (ep.Listener != null)
                    {
                        builder.AppendLine(ep.Listener.Uri.ToString());
                    }
                }
                m_tracer.InfoFormat("Service host [{0}] started. Listening on following base URIs:{1}{2}",
                    m_instanceName, Environment.NewLine, builder);
            }
        }