patryk_szwed

service2

May 13th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.Text;
  7. using System.Threading;
  8.  
  9. namespace WcfServiceLibrary2
  10. {
  11. // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
  12. [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
  13. public class myCallbackKalkulator : ICallbackKalkulator
  14. {
  15. private double result;
  16. private ICallbackHandler callback = null;
  17. public myCallbackKalkulator()
  18. {
  19. callback = OperationContext.Current.GetCallbackChannel<ICallbackHandler>();
  20. }
  21.  
  22. public void Factorial(double n)
  23. {
  24. Console.WriteLine("...call of Factorial({0})", n);
  25. Thread.Sleep(1000);
  26. result = 1;
  27. for (int i = 1; i <= n; i++)
  28. {
  29. result *= i;
  30. }
  31. callback.FactorialCB(result);
  32. }
  33.  
  34. public void CalcSomething(int sek)
  35. {
  36. Console.WriteLine("...call of CalcSomething({0})", sek);
  37. if (sek < 10)
  38. {
  39. Thread.Sleep(sek * 1000);
  40. }
  41. else
  42. {
  43. Thread.Sleep(1000);
  44. }
  45. callback.CalcSomethingCB("Calculations lasted " + (sek + 1) + " second(s)");
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment