Exemple #1
0
        private async Task RegisterService()
        {
            var list = new List <AddressModel>();

            foreach (var m in ServiceHostManager.GetContractInfo())
            {
                var model = new AddressModel()
                {
                    Url              = m.url,
                    ServiceNodeName  = ServiceManageHelper.ParseServiceName(m.contract),
                    EndpointNodeName = ServiceManageHelper.EndpointNodeName(this._node_id),
                };
                list.Add(model);
            }

            foreach (var m in list)
            {
                var service_path = this._base_path + "/" + m.ServiceNodeName;
                await this.Client.EnsurePath(service_path);

                var path = service_path + "/" + m.EndpointNodeName;
                var data = this._serializer.Serialize(m);
                if (await this.Client.ExistAsync_(path))
                {
                    await this.Client.SetDataAsync_(path, data);
                }
                else
                {
                    //创建临时节点,服务端下线自动删除
                    await this.Client.CreateNode_(path, CreateMode.EPHEMERAL, data);
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //ServiceHostManager manager = new ServiceHostManager();
            //manager.Run();

            ServiceHostBootstrapper bootstrapper = new ServiceHostBootstrapper();

            bootstrapper.Run();

            DatabaseInitializer.Initialize();

            //ServiceHostManager manager = bootstrapper._container.GetExportedValue<IServiceHostManager>() as ServiceHostManager;

            IServiceLocator    serviceLocator = bootstrapper._container.GetExportedValue <IServiceLocator>();
            ServiceHostManager manager        = serviceLocator.GetInstance <IServiceHostManager>() as ServiceHostManager;

            manager._container = bootstrapper._container;
            manager.LookupServices();

            int basePort = 50000;

            foreach (var host in manager.Services)
            {
                if (!host.UpdateAddressPort(basePort))
                {
                    Console.WriteLine("Hosting Service: " + host.Meta.Name + " UpdateAddressPort " + basePort.ToString() + " failure.");
                }

                //foreach (var address in service.Description.Endpoints)
                //{
                //    Console.WriteLine("Hosting Service: " + service.Meta.Name + " at " + address.Address.Uri);
                //}

                Debug.Assert(host.Description.Endpoints.Count == 1);

                host.Open();

                OperationContext operationContext = OperationContext.Current;
                InstanceContext  instanceContext  = operationContext.InstanceContext;
                ILighterService  service          = instanceContext.GetServiceInstance() as ILighterService;
                service.Initialize();

                var address = host.Description.Endpoints[0];
                Console.WriteLine("Hosting Service: " + host.Meta.Name + " at " + address.Address.Uri);

                //basePort++;
            }

            Console.ReadKey();

            foreach (var service in manager.Services)
            {
                service.Close();
            }
        }
Exemple #3
0
 public static void Serv()
 {
     try
     {
         ServiceHostManager.StartService("http://localhost:10000/", typeof(WCF).Assembly);
         Console.WriteLine("服务已启动");
         Console.ReadKey();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.GetInnerExceptionAsJson());
     }
     finally
     {
         Lib.core.LibReleaseHelper.DisposeAll();
     }
 }
Exemple #4
0
        public static void DisposeAll()
        {
            try
            {
                //startup tasks
                LibStartUpHelper.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //wcf service host
                ServiceHostManager.DisposeService();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //akka system
                AkkaSystemManager.Instance.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //task
                TaskManager.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //redis
                RedisClientManager.Instance?.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //关闭rabbitmq
                RabbitMQClientManager.Instance?.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //关闭ES搜索
                ElasticsearchClientManager.Instance?.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //zookeeper
                //ZooKeeperClientManager.Instance?.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //IOC
                AppContext.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            try
            {
                //httpclient
                HttpClientManager.Instance.Dispose();
            }
            catch (Exception e)
            {
                e.AddErrorLog();
            }

            //回收内存
            GC.Collect();
        }
 public WcfHoster(ServiceHostManager serviceHostManager)
 {
     _serviceHostManager = serviceHostManager;
 }