zoukankan      html  css  js  c++  java
  • WCF发布多个服务

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using WcfServiceLibrary1;
    using System.ServiceModel.Configuration;
    using System.Configuration;
    using System.Reflection;
    using System.ServiceModel;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                //将指定的客户端配置文件作为Configuration打开
                Configuration conf = ConfigurationManager.OpenExeConfiguration(Assembly.GetCallingAssembly().Location);
                ServiceModelSectionGroup svcmode = (ServiceModelSectionGroup)conf.GetSectionGroup("system.serviceModel");
    
                ServiceHost host = null;
                foreach (ServiceElement el in svcmode.Services.Services)
                {
                    //string serviceNameSpace = el.Name.Substring(0, el.Name.LastIndexOf('.'));
                    string serviceNameSpace = el.Name.Split('.')[0];
                    Type svcType = Type.GetType(el.Name + "," + serviceNameSpace);
                    if (svcType == null)
                        throw new Exception("Invalid Service Type " + el.Name + " in configuration file.");
                    host = new ServiceHost(svcType);
    
                    host.Opened += delegate
                    {
                        Console.WriteLine(el.Name + "服务已经启动了");
                    };
    
                    host.Open();
                }
             
                   Console.Read();
            }
        }

    这里注意引入System.Configuration命名空间

    运行结果:

  • 相关阅读:
    css
    ubuntu 解压zip 文件乱码
    常用 Git 命令清单
    phpstorm git配置
    github ssh秘钥配置
    ubuntu 安装phpunit
    ubuntu 安装php xdebug
    nginx压缩,缓存
    mysql中max_allowed_packet参数的配置方法(避免大数据写入或者更新失败)
    putty登录显示IP
  • 原文地址:https://www.cnblogs.com/smiler/p/3215046.html
Copyright © 2011-2022 走看看