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();
}

最新文章

  1. ASP.NET MVC Routing、Areas、URLs
  2. Java 抽象类的理解
  3. IplImage 结构解读
  4. 自定义控件之 TextBox
  5. MVC显示Base64图片
  6. 三种dedecms调用相关文章的方法
  7. window.open被IE拦截的解决办法
  8. SQL中ISNULL的使用
  9. VS 2012 插件卸载(删除自己安装的插件)
  10. win 8.1_64 安装usb 转串口驱动
  11. Edit Individual GridView Cells in ASP.NET
  12. vim中多行注释 和 删除多行注释
  13. 利用instsrv和srvany来手动安装服务
  14. 烧录口被初始化为普通IO
  15. spring简单笔记
  16. python模块安装
  17. 一种轻量级的微信小程序日志监控的方法
  18. Switch在swift中的使用
  19. day 7-12 数据库的基本操作和存储引擎
  20. VMware Workstation Pro 14.1.1 正式版

热门文章

  1. 【转】Oracle当中扫描数据的方法
  2. ffmpeg解码音频流
  3. JAVA分布式事务原理及应用(转)
  4. POJ 3026(BFS+prim)
  5. POJ 2676
  6. centos6.5 tomcat开机启动
  7. 自动化运维工具ansible学习+使用ansible批量推送公钥到远程主机
  8. Html5 新标签
  9. Jquery 提示还可以输入的字数,将多余的字数截取掉
  10. C#文件夹和文件操作