WcfServiceManager.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ServiceModel;
  6. using Aitex.Core.RT.Log;
  7. using System.Windows;
  8. using Aitex.Core.Util;
  9. namespace Aitex.Core.WCF
  10. {
  11. public class WcfServiceManager : Singleton<WcfServiceManager>
  12. {
  13. List<ServiceHost> _serviceHost = new List<ServiceHost>();
  14. public void Initialize(Type[] serviceType)
  15. {
  16. foreach (Type t in serviceType)
  17. {
  18. try
  19. {
  20. ServiceHost host = new ServiceHost(t);
  21. host.Open();
  22. _serviceHost.Add(host);
  23. }
  24. catch (Exception ex)
  25. {
  26. LOG.Write(0,MECF.Framework.Common.Equipment.ModuleName.System, t.Name, ex.Message);
  27. throw new ApplicationException(string.Format("初始化{0}服务失败,", t.ToString(), ex.Message));
  28. }
  29. }
  30. }
  31. public void Terminate()
  32. {
  33. foreach (var serviceHost in _serviceHost)
  34. {
  35. try
  36. {
  37. serviceHost.Abort();
  38. serviceHost.Close();
  39. }
  40. catch (Exception ex)
  41. {
  42. LOG.Write(eEvent.ERR_EXCEPTION, MECF.Framework.Common.Equipment.ModuleName.System, string.Format("关闭'{0}'服务失败 {1}", serviceHost.Description.Name, ex.Message));
  43. }
  44. }
  45. }
  46. }
  47. }