I need to do something similar when I perform an automatic update of a remote WCF service. In your Restart () method, close the host:
try { host.Description.Endpoints.Where(x => !x.Address.ToString().EndsWith("MEX")).ForEach(endpoint => _log.InfoFormat("Closing {0}", endpoint.Address)); host.Close(TimeSpan.FromSeconds(5)); } catch (Exception) { host.Abort(); }
I wait for my update to be applied, and then after success or failure I will open the host again using the same code that I used to run it first.
If you just want to restart right away, you can just call host.Open (), or you can set a timer to call it, etc.
try { host.Open(); host.Description.Endpoints.Where(x => !x.Address.ToString().EndsWith("MEX")).ForEach(endpoint => _log.InfoFormat("Host opened at: {0}", endpoint.Address)); } catch (Exception ex) { _log.Error("Unable to open host.", ex); }
source share