Host.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. namespace Winsoft.GOV.WCF
  8. {
  9. public class Host
  10. {
  11. private static ServiceHost adapter;
  12. public static bool Start()
  13. {
  14. try
  15. {
  16. adapter = new ServiceHost(typeof(PowerMettersService));
  17. adapter.Open();
  18. Log("Winsoft.GOV.WCF started!");
  19. return true;
  20. }
  21. catch (Exception ex)
  22. {
  23. Log("Start Service failed:{0}" + ex.ToString());
  24. return false;
  25. }
  26. }
  27. public static void Stop()
  28. {
  29. try
  30. {
  31. if (adapter != null)
  32. {
  33. adapter.Close();
  34. adapter = null;
  35. }
  36. }
  37. catch (Exception ex)
  38. {
  39. Log("Stop Service failed:{0}" + ex.ToString());
  40. }
  41. }
  42. private static void Log(string msg)
  43. {
  44. System.Console.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
  45. System.Console.WriteLine(":{0}", msg);
  46. }
  47. }
  48. }