Hello, I have created a windows service and I would like it to access a web cache. I have stored a datatable in web cache and I would like for my windows service to access and process it. Is this possible?
Accessing ASP.Net's runtime Cache requires access to the w3wp process. I'm uncertain of the restrictions in cross-process marshaling of objects specific to the w3wp process.
Depending on what you need to when you "process" your cache entries, consider adding a simple web service to your website and protect it with credentials. Then, you can access the cache objects in the background of your service calls and act on those on behalf of your Windows service.
Not directly. Your Windows Service is running as a separate process from the application pool your web application is running as. You'll need to use some form in inter-process communication. You may also want to consider the possibility that you'll eventually want or need to deploy the Windows Service on a different server than your web application.
You can expose a web service from your web application that your service calls to access/update the cached data as jro suggested. Or, you could use SQL Server to store the data and SQL Notification Services to alert the Windows Service that the data had changed. That would prevent you from having to continuously poll a web service from your Windows Service. Another option would be to expose a WCF endpoint from your Windows Service that you could invoke from your web application to pass the data.
Choosing a pattern really depends on your requirements - particularly which end of the communication will be initiating updates.
Why not take a look at memcached for .NET? It is a distributed caching system, which both your website and windows service could call on. There is an example here on CodeProject.