Advertisement
patryk_szwed

host

May 13th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.ServiceModel;
  5. using System.ServiceModel.Description;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using WcfServiceLibrary1;
  9. using WcfServiceLibrary2;
  10.  
  11. namespace host
  12. {
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. Uri baseAddress1 = new Uri("http://localhost:10010/MyBaseName/endpoint1");
  18. ServiceHost myHost1 = new ServiceHost(typeof(myCCalculator), baseAddress1);
  19. Uri baseAddress2 = new Uri("http://localhost:20010/MyBaseName/endpoint2");
  20. ServiceHost myHost2 = new ServiceHost(typeof(myCallbackKalkulator), baseAddress2);
  21. WSDualHttpBinding myBanding2 = new WSDualHttpBinding();
  22. try
  23. {
  24. // Add the endpoint
  25. // BasicHttpBinding myBinding = new BasicHttpBinding();
  26. // myHost1.AddServiceEndpoint(typeof(ICCalculator), myBinding, "endpoint1");
  27.  
  28. ServiceEndpoint endpoint1 =
  29. myHost1.AddServiceEndpoint(typeof(ICCalculator), new BasicHttpBinding(), baseAddress1);
  30. ServiceEndpoint endpoint2 =
  31. myHost2.AddServiceEndpoint(typeof(ICallbackKalkulator), myBanding2, "CallbackKalkulator");
  32. // Metadata:
  33. ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
  34. smb.HttpGetEnabled = true;
  35. myHost1.Description.Behaviors.Add(smb);
  36. ServiceMetadataBehavior smb2 = new ServiceMetadataBehavior();
  37. smb2.HttpGetEnabled = true;
  38. myHost2.Description.Behaviors.Add(smb2);
  39. myHost1.Open();
  40. myHost2.Open();
  41. Console.WriteLine("--->CCalculator is running.");
  42. Console.WriteLine("--->CallbackKalkulator is running.");
  43. Console.WriteLine("--->Press <ENTER> to stop.\n");
  44. Console.ReadLine(); // wait for stop
  45. myHost1.Close();
  46. myHost2.Close();
  47. Console.WriteLine("---> Service finished work.");
  48. }
  49. catch (CommunicationException ce)
  50. {
  51. Console.WriteLine("Exception occurred: {0}", ce.Message);
  52. myHost1.Abort();
  53. myHost2.Abort();
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement