To keep this simple, I'm going to pretend that all I want to do is record the number of times my WCF Service is called from a client in a static field called “Hits” and since a IIS hosted WCF service terminates if no requests are made after a period of time, “Hits” will be reset to zero when this happens, losing the data. I don't want each request fetching this data, but just getting it from the static field.
My questions are:
1. What event can be trapped to read a starting value from a DB when the service starts (not a session start but the actual service start);
2. How can I make the static field “Hits” threadsafe, since multiple workerthreads for this WCF will all be trying to update this static field;
3. What event can be trapped, when the service self-terminates, to save the value in “Hits” to the DB.