Guest User

Untitled

a guest
Jul 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. //example:
  2. Service<IProxyInterface>.Use(service => service.MyAwesomeMethodCall());
  3.  
  4. //code:
  5. public static class Service<T>
  6. {
  7. public static ChannelFactory<T> _channelFactory = new ChannelFactory<T>("");
  8.  
  9. public static void Use(Action<T> block)
  10. {
  11. var proxy = (IClientChannel)_channelFactory.CreateChannel();
  12. proxy.OperationTimeout = new TimeSpan(0, 5, 0);
  13. var success = false;
  14. try
  15. {
  16. block((T)proxy);
  17. proxy.Close();
  18. success = true;
  19. }
  20. finally
  21. {
  22. if (!success)
  23. {
  24. proxy.Abort();
  25. }
  26. }
  27. }
  28. }
Add Comment
Please, Sign In to add comment