WCF发布多个服务

简介: using System; using System.Collections.Generic; using System.Linq; using System.Text; using WcfServiceLibrary1; using System.
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命名空间

运行结果:

目录
相关文章
|
9月前
|
前端开发
WCF更新服务引用报错的原因之一
WCF更新服务引用报错的原因之一
|
8月前
|
C# 数据安全/隐私保护
c#如何创建WCF服务到发布(SqlServer版已经验证)
c#如何创建WCF服务到发布(SqlServer版已经验证)
38 0
|
8月前
|
安全 数据库连接 数据库
WCF服务创建到发布(SqlServer版)
在本示例开始之前,让我们先来了解一下什么是wcf? wcf有哪些特点? wcf是一个面向服务编程的综合分层架构。该架构的项层为服务模型层。 使用户用最少的时间和精力建立自己的软件产品和外界通信的模型。它使得开发者能够建立一个跨平台的安全、可信赖、事务性的解决方案。且能与已有系统兼容写作。 简单概括就是:一组数据通信的应用程序开发接口。
57 0
Visual Studio 2022 创建 WCF服务 找不到
Visual Studio 2022 创建 WCF服务 找不到
|
C++
WCF基础教程(二)——解析iis8和iis8.5+VS2013发布wcf服务问题
WCF基础教程(二)——解析iis8和iis8.5+VS2013发布wcf服务问题
102 0
WCF基础教程(二)——解析iis8和iis8.5+VS2013发布wcf服务问题
WCF使用纯代码的方式进行服务寄宿
服务寄宿的目的是为了开启一个进程,为WCF服务提供一个运行的环境。通过为服务添加一个或者多个终结点,使之暴露给潜在的服务消费,服务消费者通过匹配的终结点对该服务进行调用,除去上面的两种寄宿方式,还可以以纯代码的方式实现服务的寄宿工作。
849 0
|
Windows
WCF服务寄宿到IIS
一.WCF简介: Windows Communication Foundation(WCF)是由微软开发的一系列支持数据通信的应用程序框架,可以翻译为Windows 通讯开发平台。整合了原有的windows通讯的 .net Remoting,WebService,Socket的机制,并融合有HTTP和FTP的相关技术。
1046 0
WCF服务自我寄宿
WCF服务的寄宿方式 WCF寄宿方式是一种非常灵活的操作,可以寄宿在各种进程之中,常见的寄宿有: IIS服务、Windows服务、Winform程序、控制台程序中进行寄宿,从而实现WCF服务的运行,为调用者方便、高效提供服务调用。
994 0
|
网络架构
(纯代码)快速创建wcf rest 服务
因为有一个小工具需要和其它的业务对接数据,所以就试一下看能不能弄一个无需配置快速对接的方法出来,百(以)度(讹)过(传)后(讹),最后还是对照wcf配置对象调试出来了: 1.创建WebHttpBinding 2.
978 0