By default a WCF service exposed via http protocol is not enabled to use some features from the ASP.NET pipeline such as file and url authorization and session state. That happens because WCF services have two different run modes:
- Mixed transport mode: This is the default mode and it is completely independent of the transport and environment;
- ASP.NET compatibility mode: Allows the WCF service to use the features from the ASP.NET pipeline.
To achieve that you may define in the web.config the aspNetCompatibilityEnabled attribute flag from the serviceHostingEnvironment element as shown below:
In your service implementation you must use the System.ServiceModel.Activation.AspNetCompatibilityRequirements attribute to check whether the service is running in compatibility mode or not before the execution of the method body.
The code snippet below shows a service implementation that requires the compatibility mode to be enabled. Since it’s enabled the code will use a value stored in a session object:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class FooService : IFoo
public decimal M()
if (HttpContext.Current.Session[“StoredValue”] != null)