12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- using Aitex.Core.RT.Log;
- using System.Windows;
- using Aitex.Core.Util;
- namespace Aitex.Core.WCF
- {
- public class WcfServiceManager : Singleton<WcfServiceManager>
- {
- List<ServiceHost> _serviceHost = new List<ServiceHost>();
- 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.Error(string.Format("Failed to open WCF service '{0}'。\n Please check the configuration and restart the program.", ex.Message));
- throw new ApplicationException(string.Format("Initialization of {0} service failed,", t.ToString(), ex.Message));
- }
- }
- }
- public void Terminate()
- {
- foreach (var serviceHost in _serviceHost)
- {
- try
- {
- serviceHost.Abort();
- serviceHost.Close();
- }
- catch (Exception ex)
- {
- LOG.Error(string.Format("Failed to close '{0}' service", serviceHost.Description.Name), ex);
- }
- }
- }
- }
- }
|