Where to configure and save application state in WCF Service Library project?

I have something that I want to initialize and use throughout the WCF service library. If it were on an ASP.NET site, I would do it in the Application_Start method for global.asax, but what is equivalent for the WCF Service Library?

+4
source share
3 answers

I use a static singleton, which I lazy-initialize, where I keep the entire state of the application, and I feel rude every time I do this.

+3
source

You can create WCF session components.

Please see my answer on this question: Session wcf service in Silverlight

You can even make long-term session objects that retain their state after you disconnect from them (saving it to a file or SQL server). Chapter 4 of Yuval Lowy’s book also details this.

Is this what you are looking for?

+2
source

I'm still in training mode right now with WCF, but I think the most elegant way to actually do this is to define your own class (s) that hold state and implement them for the IExtension interface.

See this article for a review: http://blogs.msdn.com/b/drnick/archive/2007/02/15/stashing-data-in-extensible-objects.aspx

And this one for very smart use with a timer: http://social.msdn.microsoft.com/Forums/vstudio/en-US/2793580f-b91a-4d4d-b98f-b7dcab70710a/wcf-periodic-methods-call-multithread

+1
source

All Articles