Dan Sewell
Dan Sewell

Reputation: 1290

Running method on load of WCF service

I have a wcf service with my [OperationContract]'s which are triggered by the client. But I want to run a method in my WCF service that runs when the service is started (ie; when I start my service, after a server reboot I want to fill a dictionary with items from a database). Thanks.

Upvotes: 2

Views: 906

Answers (1)

Jethro
Jethro

Reputation: 5916

Why don't you just check if the dictionary is empty, if it is empty then you can get the values from the database.

If you do it like this then you can also have Cache type of effect were you could "Expire" you dictionary so it get re-populated every X hours or so?

From the following link on SO it looks like you can use Global.asax file to find out when Service starts aswell.

Upvotes: 5

Related Questions