If you self-host (i.e. write your WCF host yourself) - sure, no problem, do whatever you need to do before you call .Open()
on the ServiceHost
.
ServiceHost host = new ServiceHost(typeof(YourServiceClass));
// do your initialization here
........
host.Open();
If you're using IIS or WAS or AppFabric to host your WCF service: I doubt it, since those are "message-based" activation server, e.g. they start up a service host to handle a request on demand, when a request comes in, and I'm not aware of any extension points to get into the initialization process if you're using the regular ServiceHost
class for hosting.
That said: you can of course define your own descendants of ServiceHost
- derive your custom service host from ServiceHost
or ServiceHostBase
- those should give you points to get into the initialization process (overriding the InitializeRuntime
method, or responding to the Opening
event).
See the MSDN docs on: