Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 22nd, 2012  |  syntax: None  |  size: 1.70 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Duplex channel Faulted event does not rise on second connection attempt
  2. FooServiceClient Create()
  3. {
  4.     var client = new FooServiceClient(ChannelBinding);
  5.     client.Faulted += this.FaultedHandler;
  6.     client.Ping(); // An empty service function to make sure connection is OK
  7.     return client;
  8. }
  9.  
  10. BarServiceClient Create()
  11. {
  12.     var duplexClient = new BarServiceClient(new InstanceContext(this.barServiceCallback));
  13.     duplexClient.Faulted += this.FaultedHandler;
  14.     duplexClient.Ping(); // An empty service function to make sure connection is OK
  15.     return duplexClient;
  16. }
  17.  
  18. public class Watcher
  19. {
  20. public Watcher()
  21. {
  22.     this.CommunicationObject = this.Create();
  23. }
  24.  
  25. ICommunicationObject CommunicationObject { get; private set; }
  26.  
  27. void FaultedHandler(object sender, EventArgs ea)
  28. {
  29.     this.CommunicationObject.Abort();
  30.     this.CommunicationObject.Faulted -= this.FaultedHandler;
  31.     this.CommunicationObject = this.Create();
  32. }
  33. }
  34.        
  35. BarServiceClient Create()
  36. {
  37.     var duplexClient = new BarServiceClient(new InstanceContext(this.barServiceCallback));
  38.     duplexClient.Faulted += this.FaultedHandler;
  39.     duplexClient.Closed += this.ClosedHandler;
  40.     duplexClient.Ping(); // An empty service function to make sure connection is OK
  41.     return duplexClient;
  42. }
  43.  
  44. public class Watcher
  45. {
  46. public Watcher()
  47. {
  48.     this.CommunicationObject = this.Create();
  49. }
  50.  
  51. ICommunicationObject CommunicationObject { get; private set; }
  52.  
  53. void FaultedHandler(object sender, EventArgs ea)
  54. {
  55.     this.CommunicationObject.Abort();
  56. }
  57.  
  58. void ClosedHandler(object sender, EventArgs ea)
  59. {
  60.     this.CommunicationObject.Faulted -= this.FaultedHandler;
  61.     this.CommunicationObject.Closed -= this.ClosedHandler;
  62.     this.CommunicationObject = this.Create();
  63. }
  64. }