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

  • 相关阅读:
    2018杭州初雪
    李宗盛
    张爱玲(句子迷)
    RFBnet论文笔记
    AXI总线简介、ID分析、DMA、Vivado烧录、系统集成
    axi总线之零:概述
    怎么理解 Redis 事务?
    Redis 集群最大节点个数是多少?
    怎么测试 Redis 的连通性?
    Redis 集群如何选择数据库?
  • 原文地址:https://www.cnblogs.com/fx2008/p/2241276.html
Copyright © 2011-2022 走看看