tags:

views:

1205

answers:

2

Is there an event that fires when a WCF service gets started or shut down? Hopefully, independent of whether it is self hosted or hosted in IIS?

+3  A: 

Sure, the constructor of your object (especially if you are using a Singleton style). Please pardon the shameless self promotion, but I've written two articles on how to get started with a WCF (Net.Tcp) client/server system... The first is non-IIS (to which the service starts on your own terms), the latter is how to modify the first to be hosted in IIS to which my first sentense would apply:

1) Client Server Programming with WCF

2) Duplex WCF Services Hosted in IIS Using Net.Tcp

Timothy Khouri
Singleton did the trick, thanks.
Jake Pearson
+2  A: 

ServiceHost exposes quite a few events:

http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost_events.aspx

You could hook into these events by using a custom service behavior:

http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iservicebehavior.aspx

jezell