I have a web site and a web service under the same virtual directory and some of the web pages call the web service.
When the web service is called, does IIS create a new AppDomain or does it run the web service in the same AppDomain?
Is there a setting for this? On one of my machine it appears to create a new AppDomain. Does changing application pool mode from Integrated vs Classic affect this?
An AppDomain is a . NET term. (In IIS7, AppDomains play a larger role within IIS, but for the most part it's an ASP.NET term) An AppDomain contains InProc session state (the default session state mode). So if an AppDomain is killed/recycled, all of your session state information will be lost.
The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown.
IIS Application Pools run a single worker process (by default). Within that worker process, an AppDomain
is created for each IIS Application (website). As far as I am aware, any code executing within that IIS Application will run in the same AppDomain
(unless of course you are creating your own child application domains in code yourself). You can adjust the number of worker processes per website, but realistically only do this if you are finding you are having performance issues (that cannot be resolved by segregating the application pools). If you run multiple application domains per website, code running in those separate application domains cannot share state (e.g. InProc session), and can only communicate through serialisation - not ideal.
In regards to ASP.NET and WCF; when hosted in IIS they by default run in side-by-side mode, within the same AppDomain
, this allows them to share state, but WCF requests are not processed by the ASP.NET runtime, instead calls to WCF services are intercepted and processed by the WCF runtime. (Although calls to .svc
files are still routed through ASP.NET initially). In side-by-side mode, WCF calls do not obey configuration, security, impersonation etc. that you may have configured for your ASP.NET website.
WCF on IIS can also be run in ASP.NET Compatibility mode, in which the WCF implementation is managed by a http handler, and thus are processed by the ASP.NET pipeline also. If you would consider that your services need only HTTP support, you could consider hosting the service in compatability mode to gain access to the power and flexibility of the ASP.NET pipeline.
In regards to Integrated and Classic pipeline mode, in Intergrated mode, ASP.NET is run by the w3wp.exe
as an integrated part of the IIS processing pipeline. This means that anything using custom handlers, etc, that you may have plugged into the pipeline (even when serving non-ASP.NET content, e.g. PHP), will be loaded and executed in the same AppDomain
.
In Classic mode, ASP.NET is run in its owner worker process, aspnet_wp.exe
, and is connected to the IIS processing pipeline as an ISAPI filter. I believe the same mechanics around AppDomain
usage applies here also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With