I need to run some methods before the first call of a wcf service, where do i put those methods? Where is the startup method of a WCF Service?
Obs1: my WCF Service will run on a IIS6. Obs2: i'm using .net framework 4.0.
I need to run some methods before the first call of a wcf service, where do i put those methods? Where is the startup method of a WCF Service?
Obs1: my WCF Service will run on a IIS6. Obs2: i'm using .net framework 4.0.
One way to do this is to self host your WCF services (as in not in IIS). That way you can run whatever code you want to before spinning up the services.
Another way is to add a static method call in the constructor of each service behavior implementation. That static method call would do a check to make sure that the initialization had been performed. Just make sure to deal with multi-threaded concurrency during this call.
Depending upon life time configuration of your service WCF will either instantiate the service class on every call (singlecall), for each client (session) or just once for every call of every client (singleton).
You can implement IInstanceProvider interface and take control of the instantiation process. This way you can get a chance to call methods on the class before actual wcf call is done.