I have a WCF service hosted in windows service and I there are 2 assemblies the host (.exe) and service library (.dll). When the service library is updated we have to stop the service in order to make it possible to replace the library. I would like to have IIS similar functionality, like to replace the library without restarting the service. Is it possible and how ?
IIS uses something called a shadow copy to achieve this. You could implement something similar for your service host. Basically, the idea is that before starting the service, you copy the .DLL to some other location and have the host load your service class from that copy. The host then sets up a file system monitor to listen for changes to the original file. If it detects one, it stops the service, copies the new file, and restarts.
EDIT
(1) To start a ServiceHost using a class in a specific type library, you'd have to use reflection. Something like the following:
Assembly myAssembly = Assembly.LoadFile(path);
Type serviceType = myAssembly.GetType(className);
ServiceHost serviceHost = new ServiceHost(serviceType);
It's not clear from the documentation how LoadFile resolves dependencies. You may have to hook the Assembly.ModuleResolve event to make this work.
(2) File system monitors surely incur some overhead, but in my experience, it's minimal. In any case, this is really your only option unless you want to go with an installer for updated DLLs.
(3) I have no idea why your file is locked. You'll have to troubleshoot that yourself.
Peter has one suggestion. Depending on the size and whether you can warrant it, another is to move your infrastructure to at least 2 clustered servers. This allows you to update one at a time, while the other(s) continue to take requests. As long as you version properly (contract changes == new method), this methodology works nicely, as older clients continue to get the same data regardless of your new bits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With