patryk_szwed

client

May 13th, 2019
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.ServiceModel;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using client.ServiceReference1;
  9. using client.ServiceReference2;
  10.  
  11. namespace client
  12. {
  13. class Program
  14. {
  15. static void Main(string[] args)
  16. {
  17. CCalculatorClient client1 = new CCalculatorClient("endpoint1");
  18. ComplexNum lz1 = new ComplexNum();
  19. lz1.realPart = 1.2;
  20. lz1.imagPart = 3.4;
  21. ComplexNum lz2 = new ComplexNum();
  22. lz2.realPart = 1.2;
  23. lz2.imagPart = 3.4;
  24. Console.WriteLine("\nCLIENT1");
  25. Console.WriteLine("...called addCNum(...)");
  26. ComplexNum result1 = client1.addCNum(lz1, lz2);
  27. Console.WriteLine(" addCNum(...) = ({0},{1})",
  28. result1.realPart, result1.imagPart);
  29.  
  30.  
  31. Console.WriteLine("... call of function1:");
  32. client1.Function1("Client1");
  33. Thread.Sleep(10);
  34. Console.WriteLine("...continue after function1 call");
  35. Console.WriteLine("...call of function2:");
  36. client1.Function2("Client1");
  37. Thread.Sleep(10);
  38. Console.WriteLine("...continue after function2 call");
  39. Console.WriteLine("...call of function1:");
  40. client1.Function1("Client1");
  41. Thread.Sleep(10);
  42. Console.WriteLine("...continue after function1 call");
  43. Console.WriteLine("CLIENT1 - STOP");
  44. client1.Close();
  45.  
  46. Console.WriteLine("\nCLIENT2:");
  47.  
  48. CallbackHandler myCallbackHandler = new CallbackHandler();
  49. InstanceContext instanceContext = new InstanceContext(myCallbackHandler);
  50. CallbackKalkulatorClient client2 = new CallbackKalkulatorClient(instanceContext);
  51. double value1 = 10;
  52. Console.WriteLine("...call of Factorial({0})...", value1);
  53. client2.Factorial(value1);
  54. value1 = 20;
  55. Console.WriteLine("...call of Factorial({0})...", value1);
  56. client2.Factorial(value1);
  57.  
  58. int value2 = 2;
  59. Console.WriteLine("...call of calculation of something...");
  60. client2.CalcSomething(value2);
  61. Console.WriteLine("...now I'm waiting for results");
  62. Thread.Sleep(5000);
  63.  
  64. client2.Close();
  65. Console.WriteLine("CLIENT2 - STOP");
  66. }
  67. }
  68.  
  69. class CallbackHandler : ICallbackKalkulatorCallback
  70. {
  71. public void FactorialCB(double result)
  72. {
  73. Console.WriteLine("Factorial = {0}", result);
  74. }
  75.  
  76. public void CalcSomethingCB(string info)
  77. {
  78. Console.WriteLine("Calculations: {0}", info);
  79.  
  80. }
  81. }
  82. }
Add Comment
Please, Sign In to add comment