LabellerServer.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.ServiceModel;
  3. using System.ServiceModel.Description;
  4. namespace AIPractice.LabellerServer
  5. {
  6. class LabellerServer
  7. {
  8. private ServiceHost _host;
  9. public void Start()
  10. {
  11. Uri baseAddress = new Uri("http://localhost:8866/LabellerService");
  12. // Create the ServiceHost.
  13. _host = new ServiceHost(typeof(LabellerService), baseAddress);
  14. var basicHttpBinding = new BasicHttpBinding();
  15. basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
  16. basicHttpBinding.MaxBufferSize = int.MaxValue;
  17. basicHttpBinding.MaxBufferPoolSize = int.MaxValue;
  18. _host.AddServiceEndpoint(typeof(IAccountService), basicHttpBinding, baseAddress);
  19. _host.AddServiceEndpoint(typeof(ILabelService), basicHttpBinding, baseAddress);
  20. _host.AddServiceEndpoint(typeof(IUpgradeService), basicHttpBinding, baseAddress);
  21. _host.AddServiceEndpoint(typeof(IReviewService), basicHttpBinding, baseAddress);
  22. // Enable metadata publishing.
  23. ServiceMetadataBehavior smb = new ServiceMetadataBehavior
  24. {
  25. HttpGetEnabled = true,
  26. };
  27. smb.MetadataExporter.PolicyVersion = PolicyVersion.Default;
  28. _host.Description.Behaviors.Add(smb);
  29. // Open the ServiceHost to start listening for messages. Since
  30. // no endpoints are explicitly configured, the runtime will create
  31. // one endpoint per base address for each service contract implemented
  32. // by the service.
  33. _host.Open();
  34. }
  35. public void Stop()
  36. {
  37. _host?.Close();
  38. _host = null;
  39. }
  40. }
  41. }