一个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();
}
}
邮箱:steven9801@163.com
QQ: 48039387