This element defines the type the service hosting environment instantiates for a particular transport. If this element is empty, the default type is used. This element can only be used at the application or machine level configuration files.
<serviceHostingEnvironment aspNetCompatibilityEnabled="Boolean" minFreeMemoryPercentageToActivateService="Integer" multipleSiteBindingsEnabled="Boolean"> <baseAddressPrefixFilters> <add prefix="string"/> </baseAddressPrefixFilters> <serviceActivations> <add factory="String" service="String"/> </serviceActivations> <transportConfigurationTypes> <add name="String" transportConfigurationType="String" /> </transportConfigurationTypes></serviceHostingEnvironment>
The following sections describe attributes, child elements, and parent elements.
|aspNetCompatibilityEnabled||A Boolean value indicating whether the ASP.NET compatibility mode has been turned on for the current application. The default is |
When this attribute is set to
|minFreeMemoryPercentageToActivateService||An integer that specifies the minimum amount of free memory that should be available to the system, before a WCF service can be activated. Caution: Specifying this attribute along with partial trust in the web.config file of a WCF service will result in a SecurityException when the service is run.|
|multipleSiteBindingsEnabled||A Boolean value that specifies whether multiple IIS bindings per site is enabled.|
IIS consists of web sites, which are containers for virtual applications containing virtual directories. The application in a site can be accessed through one or more IIS binding. An IIS binding provides two pieces of information: a binding protocol and binding information. Binding protocol defines the scheme over which communication occurs, and binding information is the information used to access the site. An example of a binding protocol can be HTTP, whereas binding information can contain an IP address, Port, host header, etc.
IIS supports specifying multiple IIS bindings per site, which results in multiple base addresses per scheme. However, a Windows Communication Foundation (WCF) service hosted under a site allows binding to only one baseAddress per scheme.
To enable multiple IIS bindings per site for a Windows Communication Foundation (WCF) service, set this attribute to
|<baseAddressPrefixFilters>||A collection of configuration elements that specify prefix filters for the base addresses used by the service host.|
|<serviceActivations>||A configuration section that describes activation settings.|
|<transportConfigurationTypes>||A collection of configuration elements that identify the type of a particular transport.|
|serviceModel||The root element of all Windows Communication Foundation (WCF) configuration elements.|
By default, WCF services run side-by-side with ASP.NET in hosted Application Domains (AppDomain). Even though WCF and ASP.NET can coexist in the same AppDomain, WCF requests are not processed by the ASP.NET HTTP Pipeline by default. As a result, several elements of the ASP.NET application platform are not available to WCF services. These include
ASP.NET File/URL Authorization
Cookie-based Session State
Pipeline Extensibility via custom HttpModule
If your WCF services need to function in the ASP.NET context, and communicate only over HTTP, you can use WCF’s ASP.NET compatibility mode. This mode is turned on when the
aspNetCompatibilityEnabled attribute is set to
true at the application level. Service implementations must declare their ability to run in compatibility mode using the AspNetCompatibilityRequirementsAttribute class. When the compatibility mode is enabled,
ASP.NET File/URL Authorization is enforced prior to WCF authorization. An authorization decision is based on the transport-level identity of the request. Identities at the message level are ignored.
WCF service operations start to execute in the ASP.NET impersonation context. If both ASP.NET impersonation and WCF impersonation are enabled for a specific service, the WCF impersonation context applies.
HttpContext.Current can be used from WCF service code, and services are prevented from exposing non-HTTP endpoints.
WCF requests are processed by the ASP.NET pipeline. HttpModules that have been configured to act on incoming requests can also process WCF requests. These can include ASP.NET platform components (e.g., SessionStateModule), as well as custom third party modules.
The following code sample shows how to enable ASP Compatibility Mode.