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

  • 相关阅读:
    BZOJ 3626: [LNOI2014]LCA(树链剖分+离线处理)
    python备用
    STL的使用。。备忘
    DP专题
    任务
    hdu 网络流题集
    hdu KM匹配题集
    hdu 差分约束题集
    hdu 2sat题集
    Codeforces Round #261 (Div. 2)
  • 原文地址:https://www.cnblogs.com/fx2008/p/2241276.html
Copyright © 2011-2022 走看看