Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MEF + WCF Service Host?

Tags:

c#

wcf

mef

I am just getting into MEF and I have come across a problem that I cannot resolve. I have a windows service that is reading in my DLLs (via MEF) and each DLL is a WCF Service Host. When I run my windows service and read in the DLLs everything runs fine, except that whenever one of the WCF DLLs get any "activity" then they reinstantiate and then process the data coming in. I need them to just instantiate once at the beginning. Is this possible?

like image 617
Travyguy9 Avatar asked Dec 15 '09 16:12

Travyguy9


1 Answers

WCF services default to a per call instance mode. This means that a new instance of your WCF service is instantiated for each incoming method invocation. It sounds like what you're wanting is a singleton instance mode, but you really want to avoid this if scability is an issue.

The way I've gotten around this is to use the per call instance mode, but have a static data store behind the scenes that I synchronize access to. This at least allows clients to connect, even if they have to block momentarily while the data store is in use once the connection is established.

Refer to the MSDN help on System.ServiceModel.InstanceContextMode for more details.

like image 185
Matt Davis Avatar answered Sep 24 '22 00:09

Matt Davis