multithreadingwcfserviceappdomainshared-data

One or more AppDomains created server-side when multiple clients call a WCF service?


The question is pretty much in the title, but I will elaborate.

I have a Silverlight application that acts as a slightly extended user interface.

The main part of my program will run on a server to keep the shared database coherent.

This is where my question comes in: Will two clients calling a WCF service each get a thread inside that service OR will they get a full AppDomain each?

The difference is that if the first is the case they can share the DB easily, but in the second scenario they cannot - as I understand it.

EDIT: This is because the DB makes use of the Identity Map pattern [Fowler] where objects used are saved in physical memory (static singleton variable) - multiple AppDomains would mess that up.

(I asked my university teacher and searched quite a bit before asking this, seemingly, simple question)


Solution

  • The threading model for WCF services is determined by the ConcurrencyMode you configure for your service: http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode.aspx.

    Regarding AppDomains - that depends entirely on how you're hosting your service. If you're running a ServiceHost of your own, manually, there will always be exactly 1 AppDomain on the server side, unless you decide to start managing and spinning up your own.

    If you're hosting inside IIS...it's up to IIS how it handles requests. It may reuse 1 AppDomain, it may spin up multiple AppDomains (unless you override the setting in the web.config to permit only 1 AppDomain per worker process), or it may spin up multiple physical worker processes (which inherently implies multiple AppDomains) if you have web garden mode enabled.

    All this said, I'm not sure exactly why this would affect your data access strategy. Multiple threads or AppDomains should have no problem sharing a DB.