ReliableSessionBindingElement 类

定义

表示可以生成终结点之间可靠会话所需的发送和接收通道的绑定元素。

public ref class ReliableSessionBindingElement sealed : System::ServiceModel::Channels::BindingElement
public ref class ReliableSessionBindingElement sealed : System::ServiceModel::Channels::BindingElement, System::ServiceModel::Description::IPolicyExportExtension
public sealed class ReliableSessionBindingElement : System.ServiceModel.Channels.BindingElement
public sealed class ReliableSessionBindingElement : System.ServiceModel.Channels.BindingElement, System.ServiceModel.Description.IPolicyExportExtension
type ReliableSessionBindingElement = class
    inherit BindingElement
type ReliableSessionBindingElement = class
    inherit BindingElement
    interface IPolicyExportExtension
Public NotInheritable Class ReliableSessionBindingElement
Inherits BindingElement
Public NotInheritable Class ReliableSessionBindingElement
Inherits BindingElement
Implements IPolicyExportExtension
继承
ReliableSessionBindingElement
实现

示例

ReliableSessionBindingElement可以将其添加到任何自定义绑定。 这是使用以下配置元素完成的。

<bindings>
    <customBinding>
        <binding configurationName="ReliabilityHTTP">
            <reliableSession/>
        </binding>
    </customBinding>
</bindings>

以下示例代码演示如何在代码中使用 ReliableSessionBindingElement

Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");

// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    // Create a custom binding that contains two binding elements.
    ReliableSessionBindingElement reliableSession = new ReliableSessionBindingElement();
    reliableSession.Ordered = true;

    HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
    httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
    httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

    CustomBinding binding = new CustomBinding(reliableSession, httpTransport);

    // Add an endpoint using that binding.
    serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, "");

    // Add a MEX endpoint.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.HttpGetUrl = new Uri("http://localhost:8001/servicemodelsamples");
    serviceHost.Description.Behaviors.Add(smb);

    // Open the ServiceHostBase to create listeners and start listening for messages.
    serviceHost.Open();

    // The service can now be accessed.
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <ENTER> to terminate service.");
    Console.WriteLine();
    Console.ReadLine();

    // Close the ServiceHostBase to shutdown the service.
    serviceHost.Close();
}
Dim baseAddress As New Uri("http://localhost:8000/servicemodelsamples/service")

' Create a ServiceHost for the CalculatorService type and provide the base address.
Using serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)
    ' Create a custom binding that contains two binding elements.
    Dim reliableSession As New ReliableSessionBindingElement()
    reliableSession.Ordered = True

    Dim httpTransport As New HttpTransportBindingElement()
    httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous
    httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard

    Dim binding As New CustomBinding(reliableSession, httpTransport)

    ' Add an endpoint using that binding.
    serviceHost.AddServiceEndpoint(GetType(ICalculator), binding, "")

    ' Add a MEX endpoint.
    Dim smb As New ServiceMetadataBehavior()
    smb.HttpGetEnabled = True
    smb.HttpGetUrl = New Uri("http://localhost:8001/servicemodelsamples")
    serviceHost.Description.Behaviors.Add(smb)

    ' Open the ServiceHostBase to create listeners and start listening for messages.
    serviceHost.Open()

    ' The service can now be accessed.
    Console.WriteLine("The service is ready.")
    Console.WriteLine("Press <ENTER> to terminate service.")
    Console.WriteLine()
    Console.ReadLine()

    ' Close the ServiceHostBase to shutdown the service.
    serviceHost.Close()
End Using

注解

提供会话,还可以选择提供有序的邮件传递。 此实现的会话可以跨 SOAP 和传输中介。

每个绑定元素表示发送或接收消息时的处理步骤。 在运行时,绑定元素创建生成发送和接收消息所需的传出通道堆栈和传入通道堆栈所需的通道工厂和侦听器。 堆栈 ReliableSessionBindingElement 中提供了一个可选层,可在终结点之间建立可靠的会话并配置此会话的行为。

下表中的标准绑定上提供了该 ReliableSessionBindingElement 绑定。

Binding 默认
NetTcpBinding 关闭
WSHttpBinding 关闭
WSDualHttpBinding 打开(必需)

构造函数

名称 说明
ReliableSessionBindingElement()

初始化 ReliableSessionBindingElement 类的新实例。

ReliableSessionBindingElement(Boolean)

初始化类的新实例,该实例 ReliableSessionBindingElement 指定消息传递是否必须保留消息的发送顺序。

属性

名称 说明
AcknowledgementInterval

获取或设置目标在向由工厂创建的可靠通道上的消息源发送确认之前等待的时间间隔。

FlowControlEnabled

获取或设置一个值,该值指示可靠会话是否已启用流控制。

InactivityTimeout

获取或设置服务在关闭前保持非活动状态的时间间隔。

MaxPendingChannels

获取或设置可在可靠会话期间挂起的最大通道数。

MaxRetryCount

获取或设置在可靠会话期间消息尝试传输的最大次数。

MaxTransferWindowSize

获取或设置发送缓冲区或接收缓冲区中可存在的最大消息数。

Ordered

获取或设置一个值,该值指示消息传递是否必须保留消息的发送顺序。

ReliableMessagingVersion

获取或设置绑定元素指定的 WS-ReliableMessaging 的版本。

方法

名称 说明
BuildChannelFactory<TChannel>(BindingContext)

返回一个工厂,该工厂创建支持可靠会话的指定类型的通道。

BuildChannelListener<TChannel>(BindingContext)

返回一个侦听器,该侦听器接受支持可靠会话的指定类型的通道。

CanBuildChannelFactory<TChannel>(BindingContext)

返回一个值,该值指示是否可以为通道生成通道工厂,并提供可支持可靠会话的上下文。

CanBuildChannelListener<TChannel>(BindingContext)

返回一个值,该值指示是否可以为通道和上下文生成通道侦听器,前提是该通道可以支持可靠会话。

Clone()

创建当前可靠会话绑定元素的副本。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetProperty<T>(BindingContext)

从其绑定上下文中获取指定类型的属性。

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

显式接口实现

名称 说明
IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

将可靠会话绑定元素中包含的信息映射到 WSDL 元素,使远程终结点能够使用可靠会话访问服务。

适用于