简体   繁体   中英

Alternative to dictionary in WCF Service

I have a WCF webservice, which when the user subscribes (its a WP7 push notification service) it adds a Guid and Uri to the dictionary. My issue is, when the application stops or restarts the dictionary is obviously emptied.

I would like suggestions for easy and simple alternative ways to store the data whilst minimising memory requirements. This application is running on IIS7 with .net4.

I just need to add to the 'dictionary' and check if it Contains a value. fairly simple really.

Well, in order to keep the data present across server restarts, you obviously need to persist it.

There are two obvious possibilities here:

  • Using a database
  • Storing the data in a file

I would suggest a database would be the best approach here - it's going to be much simpler to get it to work with multiple WCF servers etc than reading and updating a shared file.

Now you may want to keep a cache of results in your server as well, in the form of a dictionary - it depends on what the access tends to look like, whether the data is ever updated (leading to the tricky issue of cache invalidation) and how important your latency requirements are. (If this is a request from a phone, then I suspect the latency of getting the request to your server to start with will dwarf the latency added by a simple database access using an indexed lookup.)

When you store something in a Dictionary in your code, it persists only up to the duration of the code execution. In other words, your dictionary's lifetime is limited to your codes execution. To have longer storage, you have to use other mechanisms like Session or Application . But if you want the lifetime of your storage pass application recycling , then you should think of storing your data in database.

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