using Aitex.Core.Util;
using System;
using System.Collections.Generic;
using System.ServiceModel;
namespace Common
{
///
/// Wcf的管理模块
///
public class WcfServiceManager : Singleton
{
List _serviceHost = new List();
public void Initialize(Type[] serviceType)
{
foreach (Type t in serviceType)
{
try
{
ServiceHost host = new ServiceHost(t);
host.Open();
_serviceHost.Add(host);
}
catch (Exception ex)
{
//LOG.Write(0, MECF.Framework.Common.Equipment.ModuleName.System, t.Name, ex.Message);
throw new ApplicationException(string.Format("初始化{0}服务失败,", t.ToString(), ex.Message));
}
}
}
public void Terminate()
{
foreach (var serviceHost in _serviceHost)
{
try
{
serviceHost.Abort();
serviceHost.Close();
}
catch (Exception ex)
{
//LOG.Write(eEvent.ERR_EXCEPTION, MECF.Framework.Common.Equipment.ModuleName.System, string.Format("关闭'{0}'服务失败 {1}", serviceHost.Description.Name, ex.Message));
}
}
}
}
}