AspNetCompatibilityRequirementsMode Enum

Definition

Specifies whether a Windows Communication Foundation (WCF) service runs, or can run, in a mode that is compatible with ASP.NET.

C#
public enum AspNetCompatibilityRequirementsMode
Inheritance
AspNetCompatibilityRequirementsMode

Fields

Name Value Description
NotAllowed 0

WCF services must run in an application domain with ASP.NET compatibility mode set to false.

Allowed 1

WCF services can run in an application domain with ASP.NET compatibility mode set to true or false.

Required 2

WCF services must run in an application domain with ASP.NET compatibility mode set to true.

Examples

Service developers can ensure that their service is only run in ASP.NET Compatibility Mode by setting the AspNetCompatibilityRequirementsAttribute.RequirementsMode property to Required, as shown in the following example:

C#
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface ICalculatorSession
{
    [OperationContract]
    void Clear();
    [OperationContract]
    void AddTo(double n);
    [OperationContract]
    void SubtractFrom(double n);
    [OperationContract]
    void MultiplyBy(double n);
    [OperationContract]
    void DivideBy(double n);
    [OperationContract]
    double Equals();
}
C#
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class CalculatorService : ICalculatorSession
{
    double result
    {   // Store result in AspNet session.
        get
        {
            if (HttpContext.Current.Session["Result"] != null)
                return (double)HttpContext.Current.Session["Result"];
            return 0.0D;
        }
        set
        {
            HttpContext.Current.Session["Result"] = value;
        }
    }

    public void Clear()
    {
    }

    public void AddTo(double n)
    {
        result += n;
    }

    public void SubtractFrom(double n)
    {
        result -= n;
    }

    public void MultiplyBy(double n)
    {
        result *= n;
    }

    public void DivideBy(double n)
    {
        result /= n;
    }

    public double Equals()
    {
        return result;
    }
}

Remarks

ASP.NET compatibility mode allows WCF services to use ASP features such as identity impersonation. It is enabled at the application level through the Web.config file and cannot be overridden by Web.config files nested in the application. When the AspNetCompatibilityRequirementsMode value is not specified for a service, the default is Allowed. For more information, see <serviceHostingEnvironment>.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1