chcong

WCF服务。利用循环,读取配置文件,打开所有的代理服务 和关闭代理服务的方法

  //list列表 ,用于存储打开的服务列表
        List<ServiceHost> _host = new List<ServiceHost>();

        /// <summary>
        /// 批量打开服务
        /// </summary>
        public void hostopen()
        {
            Configuration conf = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
            ServiceModelSectionGroup svcmod = (ServiceModelSectionGroup)conf.GetSectionGroup("system.serviceModel");
            foreach (ServiceElement el in svcmod.Services.Services)
            {
                Type svcType = Type.GetType(el.Name + "," + "Wcf_DaBu_Service");
                if (svcType == null)
                    throw new Exception("Invalid Service Type " + el.Name + " in configuration file.");
                ServiceHost aServiceHost = new ServiceHost(svcType);
                aServiceHost.Open();
                _host.Add(aServiceHost);
                MessageBox.Show(el.Name + "  服务打开");
            }
        }
        /// <summary>
        /// 利用list<T>批量关闭服务
        /// </summary>
        public void hostclose()
        {
            foreach (ServiceHost host in _host)
            {
                Console.WriteLine("关闭服务");
                host.Close();
            }
            //清空列表里面的服务
            _host.Clear();
        }

 

分类:

技术点:

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-09-07
  • 2021-08-21
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2021-06-15
  • 2022-12-23
  • 2021-07-22
  • 2021-05-26
  • 2021-11-27
  • 2021-12-16
  • 2021-11-17
相关资源
相似解决方案