zoukankan      html  css  js  c++  java
  • 一个Windows服务如何host多个wcf服务?

         一个Windows服务如何host多个wcf服务?

            protected override void OnStart(string[] args)
            {
                if (serviceHostes.Count > 0) serviceHostes.Clear();
                var configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
                ServiceModelSectionGroup serviceModelSectionGroup = (ServiceModelSectionGroup)configuration.GetSectionGroup("system.serviceModel");
                // 开启每个服务
                foreach (ServiceElement serviceElement in serviceModelSectionGroup.Services.Services)
                {               
                    var wcfServiceType = Assembly.Load("RTLS.Services").GetType(serviceElement.Name);
                    var serviceHost = new ServiceHost(wcfServiceType);              
                    serviceHostes.Add(serviceHost);
                    serviceHost.Opened += delegate
                    {
                        LogManager.WriteLog("Log", string.Format("{0}开始监听Uri为:{1}",
                        serviceElement.Name, serviceElement.Endpoints[0].Address.ToString()));
                    };
                    serviceHost.Open();               
                }           
            }

  • 相关阅读:
    Aerospike系列:4:简单的增删改查aql
    Aerospike系列:3:aerospike特点分析
    MySQL事物系列:2:事物的实现
    MySQL事物系列:1:事物简介
    MySQL 源码系列:1:窥探篇
    MySQL 内存和CPU优化相关的参数
    Aerospike系列:2:商业版和社区版的比较
    Aerospike系列:1:安装
    MDX Cookbook 08
    MDX Cookbook 07
  • 原文地址:https://www.cnblogs.com/fx2008/p/2241276.html
Copyright © 2011-2022 走看看