AspNetCompatibilityRequirementsMode 枚举

定义

指定 Windows Communication Foundation (WCF) 服务是否以与 ASP.NET 兼容的模式运行或是否可以运行。Specifies whether a Windows Communication Foundation (WCF) service runs, or can run, in a mode that is compatible with ASP.NET.

public enum class AspNetCompatibilityRequirementsMode
public enum AspNetCompatibilityRequirementsMode
type AspNetCompatibilityRequirementsMode = 
Public Enum AspNetCompatibilityRequirementsMode
继承
AspNetCompatibilityRequirementsMode

字段

Allowed 1

WCF 服务可在 ASP.NETASP.NET 兼容模式设置为 truefalse 的应用程序域中运行。WCF services can run in an application domain with ASP.NETASP.NET compatibility mode set to true or false.

NotAllowed 0

WCF 服务必须在 ASP.NETASP.NET 兼容模式设置为 false 的应用程序域中运行。WCF services must run in an application domain with ASP.NETASP.NET compatibility mode set to false.

Required 2

WCF 服务必须在 ASP.NETASP.NET 兼容模式设置为 true 的应用程序域中运行。WCF services must run in an application domain with ASP.NETASP.NET compatibility mode set to true.

示例

服务开发人员可以通过将AspNetCompatibilityRequirementsAttribute.RequirementsMode属性设置为Required, 确保其服务仅在 ASP.NET 兼容模式下运行, 如下面的示例中所示: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:

[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();
}
<ServiceContract(Namespace:="http://Microsoft.ServiceModel.Samples")> _
Public Interface ICalculatorSession

    <OperationContract()> _
    Sub Clear()
    <OperationContract()> _
    Sub AddTo(ByVal n As Double)
    <OperationContract()> _
    Sub SubtractFrom(ByVal n As Double)
    <OperationContract()> _
    Sub MultiplyBy(ByVal n As Double)
    <OperationContract()> _
    Sub DivideBy(ByVal n As Double)
    <OperationContract()> _
    Function Equal() As Double
End Interface
[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;
    }
}
    <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)> _
    Public Class CalculatorService
        Implements ICalculatorSession

        Property Result() As Double
            ' Store result in AspNet Session.
            Get
                If (HttpContext.Current.Session("Result") Is Nothing) Then
                    Return 0D
                End If
                Return HttpContext.Current.Session("Result")
            End Get
            Set(ByVal value As Double)
                HttpContext.Current.Session("Result") = value
            End Set
        End Property

        Public Sub Clear() _
 Implements ICalculatorSession.Clear
            Result = 0D
        End Sub

        Public Sub AddTo(ByVal n As Double) _
Implements ICalculatorSession.AddTo
            Result += n
        End Sub

        Public Sub SubtractFrom(ByVal n As Double) _
Implements ICalculatorSession.SubtractFrom

            Result -= n
        End Sub

        Public Sub MultiplyBy(ByVal n As Double) _
Implements ICalculatorSession.MultiplyBy

            Result *= n
        End Sub

        Public Sub DivideBy(ByVal n As Double) _
Implements ICalculatorSession.DivideBy

            Result /= n
        End Sub

        Public Function Equal() As Double _
Implements ICalculatorSession.Equal

            Return Result
        End Function
    End Class

注解

ASP.NET 兼容模式允许 WCF 服务使用诸如标识模拟等 ASP 功能。ASP.NET compatibility mode allows WCF services to use ASP features such as identity impersonation. 该服务是通过 Web.config 文件在应用程序级别启用的,并且无法由嵌套在应用程序中的 Web.config 文件重写。It is enabled at the application level through the Web.config file and cannot be overridden by Web.config files nested in the application. 如果没有为服务指定Allowed值,则默认值为。AspNetCompatibilityRequirementsModeWhen the AspNetCompatibilityRequirementsMode value is not specified for a service, the default is Allowed. 有关详细信息, 请 <参阅>serviceHostingEnvironmentFor more information, see <serviceHostingEnvironment>.

适用于