如果用self-host的方式来加载服务的话,我们一般是用这样的代码:ServiceHost host1 = new ServiceHost(typeof(UserService)); 问题是,如果当你的服务很多的时候这样做是不胜其烦的,今天在看Ingo Rammer(大名鼎鼎的《Advanced .Net Remoting》作者)的Blog的时候,看到了他解决这一问题的方法:
一.服务配置在app.config或web.config中:

 1wcf中如何Host多个WCF服务?using System;
 2wcf中如何Host多个WCF服务?using System.Collections.Generic;
 3wcf中如何Host多个WCF服务?using System.Reflection;
 4wcf中如何Host多个WCF服务?using System.Configuration;
 5wcf中如何Host多个WCF服务?using System.ServiceModel.Configuration;
 6wcf中如何Host多个WCF服务?using System.ServiceModel;
 7wcf中如何Host多个WCF服务?
 8wcf中如何Host多个WCF服务?public class ServiceHostGroup
 9}



二.服务配置在外部配置文件中:

Services.XML:

<configuredServices>
  <service type="ServiceImplementation.ArticleService, ServiceImplementation" />
</configuredServices>


ServiceHostBase.cs:

 1wcf中如何Host多个WCF服务?using System;
 2wcf中如何Host多个WCF服务?using System.Collections.Generic;
 3wcf中如何Host多个WCF服务?using System.Reflection;
 4wcf中如何Host多个WCF服务?using System.Configuration;
 5wcf中如何Host多个WCF服务?using System.ServiceModel.Configuration;
 6wcf中如何Host多个WCF服务?using System.ServiceModel;
 7wcf中如何Host多个WCF服务?using System.Xml;
 8wcf中如何Host多个WCF服务?using System.Xml.Serialization;
 9wcf中如何Host多个WCF服务?using System.IO;
10wcf中如何Host多个WCF服务?
11wcf中如何Host多个WCF服务?public class ServiceHostGroup
12}



原文:

Start ServiceHosts for all configured Services 


相关文章: