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

  • 相关阅读:
    python 安装与pip安装
    使用通配符来解决数据1和11、12/13/14的问题
    数据库中一行变多行,拆分数据
    15-哈希表 HashTable
    13-自平衡二分搜索树 AVLTree
    12-并查集 UnionFind
    11-字典树 Trie
    10-线段树 Segment Tree
    09-堆 Heap(最大堆)
    08-映射 Map
  • 原文地址:https://www.cnblogs.com/fx2008/p/2241276.html
Copyright © 2011-2022 走看看