Caching data for a WCF service

  • Thread starter Thread starter jeff
  • Start date Start date
J

jeff

Hi there

Very new to C# so obviously thought I'd jump in the deep end first.

I want to create a WCF service that provides data from a database to a
large number of clients.

Many clients will try to connect in a very short space of time to
retrieve the same date.

To reduce the round trips to the database I want to cache the data in a
dataset.

Simply put I have a class that provides access to the data in the
dataset but I don't want a new instance of this class and hence a new
data set created every time a client connects.

What I want is for all clients to have access to read from the same set
of data and hence from the same instance of the dataset.

The service is hosted as a windows service, not through IIS.

I am assuming a new instance of the class that implements the service
contract is created with each new client? Is this correct?

Any ideas folks - can provide more info if required.
 
Thanks Peter I'd looked at that particular bestie for something else so
no problems.

I've followed the code from the help files in VS 2K8 to understand this
thing. However there is a bit of a void in my understanding between the
declaration of the service host in the windows service class and the
functionality implemented by the WCF service itself.

Is there a good guide you can point me in that describes what happens at
run time and what the interaction is between serviceHost and
MyWCFService implementation?
 
Jeff,

A lot of this is going to depend on the instancing for the service that
you are specifying.

For example, it can be set to be a singleton (one instance for all
calls), sessionful (one instance per proxy), or per-call (one instance per
call on a proxy). These will determine how your instances are created.

That's the first thing you are going to have to figure out in order to
figure out how to cache your data, as the cache is going to have a lifetime
that is relative (and slightly dependent) on this issue.

Also, you don't ^have^ to use the HttpCache from System.Web. You can
also use the Enterprise Library Caching block, or you can just store the
data in a static variable somewhere (just make sure you synchronize access
to it, as depending on the instancing of your service and the scope of the
cache, you could have multiple threads accessing it at the same time).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

WCF, Typed Datasets and DataContracts 4
WCF and duplex service contracts 1
WCF Question 17
WCF Service hangs after client crashes 1
NHibernate in WCF 1
WCF & Transactions 5
WCF POST web service 2
WCF 2

Back
Top