AspNetCompatibilityRequirementsMode AspNetCompatibilityRequirementsMode AspNetCompatibilityRequirementsMode AspNetCompatibilityRequirementsMode Enum

Определение

Указывает, выполняется ли или может ли выполняться служба 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
Наследование
AspNetCompatibilityRequirementsModeAspNetCompatibilityRequirementsModeAspNetCompatibilityRequirementsModeAspNetCompatibilityRequirementsMode

Поля

Allowed Allowed Allowed Allowed 1

Службы WCF могут работать в домене приложения с режимом совместимости с ASP.NETASP.NET, заданным как true или false.WCF services can run in an application domain with ASP.NETASP.NET compatibility mode set to true or false.

NotAllowed NotAllowed NotAllowed 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 Required Required Required 2

Службы WCF должны работать в домене приложения с режимом совместимости с ASP.NETASP.NET, заданным как true.WCF services must run in an application domain with ASP.NETASP.NET compatibility mode set to true.

Примеры

Разработчики служб могут убедиться, что служба работает только в режиме совместимости ASP.NET, задав Allowed AspNetCompatibilityRequirementsAttribute для свойства в значение Required, как показано в следующем примере:Service developers can ensure that their service is only run in ASP.NET Compatibility Mode by setting the Allowed property on the AspNetCompatibilityRequirementsAttribute 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.NETASP.NETрежим совместимости позволяет службам WCF использовать такие функции ASP, как олицетворение удостоверений.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. AspNetCompatibilityRequirementsMode Если значение не указано для службы, оно по умолчанию получает разрешенное поведение.When the AspNetCompatibilityRequirementsMode value is not specified for a service, it gets Allowed behavior by default. Дополнительные сведения см. в <разделе>serviceHostingEnvironment.For more information, see <serviceHostingEnvironment>.

Применяется к