Host.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.ServiceModel;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Winsoft.GOV.Framework;
  8. namespace Winsoft.GOV.WCF
  9. {
  10. public class Host
  11. {
  12. private static ServiceHost adapter;
  13. public static bool Start()
  14. {
  15. try
  16. {
  17. adapter = new ServiceHost(typeof(PowerMettersService));
  18. adapter.Open();
  19. FunLib.Log("Winsoft.GOV.WCF started!");
  20. return true;
  21. }
  22. catch (Exception ex)
  23. {
  24. FunLib.Log("Start Service failed:{0}" + ex.ToString());
  25. return false;
  26. }
  27. }
  28. public static void Stop()
  29. {
  30. try
  31. {
  32. if (adapter != null)
  33. {
  34. adapter.Close();
  35. adapter = null;
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. FunLib.Log("Stop Service failed:{0}" + ex.ToString());
  41. }
  42. }
  43. private static void Log(string msg)
  44. {
  45. System.Console.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
  46. System.Console.WriteLine(":{0}", msg);
  47. }
  48. }
  49. }