2

I have WCF Service-client, On Service side, If unhandled exception is thrown, the channel will get faulted, After channel is faulted i have to recreate the client side.
When i create the client i use ChannelFactory, so i need to .Abort the current channel and then create it again.
What is the benefit of doing Try Catch with Fault Exception on service side ? it wont fault the channel ?

  • My managed application contains several ServiceHost opened, How can i register their faulted state and restart a certain service from the Event Handler?

Code:

...
serviceHost.Faulted+=serviceHost_Faulted; 
...
private static void serviceHost_Faulted(object sender, EventArgs e)
{
 //How to detect the channel information ? can i cast sender to and know its implemented IService interface ?
}
ilansch
  • 4,784
  • 7
  • 47
  • 96
  • Yes, using a Try Catch and handling exceptions will prevent the service from faulting. You can also look into implementing IErrorHandler to catch any otherwise uncaught exceptions. As for the second part of your question, I'm not sure what you're trying to do - if the channel faults, it needs to be aborted, and the client will need to reconnect. The service can't reconnect for the client in any manner that I'm aware of. – Tim May 27 '13 at 18:25
  • Take a look at Carlos Figueira's blog for more information about IErrorHandler - [WCF Extensibility – IErrorHandler](http://blogs.msdn.com/b/carlosfigueira/archive/2011/06/07/wcf-extensibility-ierrorhandler.aspx) – Tim May 27 '13 at 18:26
  • Hi, yes i implement in addition a client recovery process, this is the service recovery process, i meant in my 2nd question that i register to servicehost.faulted and from the event handler invoked, to know which service went down and .about and create again. i found this great link http://muxtonmumbles.blogspot.co.il/2010/03/dynamically-creating-servicehost-for.html that last host_Faulted is what i meant. thanks tim – ilansch May 28 '13 at 06:00
  • If you look at the example you linked, the event handler casts the `sender` parameter to `ServiceHost`, and from there can access the information needed to shut down and restart the service. – Tim May 29 '13 at 07:36

0 Answers0