简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM