OptionalReliableSession 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
使用可选的预定义绑定之一时,提供对可靠会话是否启用的便捷访问。
public ref class OptionalReliableSession : System::ServiceModel::ReliableSession
public class OptionalReliableSession : System.ServiceModel.ReliableSession
type OptionalReliableSession = class
inherit ReliableSession
Public Class OptionalReliableSession
Inherits ReliableSession
- 继承
示例
以下示例演示如何创建新的可靠会话、访问和更改该会话的默认值。
private void Run()
{
WSHttpBinding b = new WSHttpBinding();
b.Name = "HttpOrderedReliableSessionBinding";
// Get a reference to the OptionalreliableSession object of the
// binding and set its properties to new values.
OptionalReliableSession myReliableSession = b.ReliableSession;
myReliableSession.Enabled = true; // The default is false.
myReliableSession.Ordered = false; // The default is true.
myReliableSession.InactivityTimeout =
new TimeSpan(0, 15, 0); // The default is 10 minutes.
// Create a URI for the service's base address.
Uri baseAddress = new Uri("http://localhost:8008/Calculator");
// Create a service host.
ServiceHost sh = new ServiceHost(typeof(Calculator), baseAddress);
// Optional: Print out the binding information.
PrintBindingInfo(b);
// Create a URI for an endpoint, then add a service endpoint using the
// binding with the latered OptionalReliableSession settings.
sh.AddServiceEndpoint(typeof(ICalculator), b, "ReliableCalculator");
sh.Open();
Console.WriteLine("Listening...");
Console.ReadLine();
sh.Close();
}
private void PrintBindingInfo(WSHttpBinding b)
{
Console.WriteLine(b.Name);
Console.WriteLine("Enabled: {0}", b.ReliableSession.Enabled);
Console.WriteLine("Ordered: {0}", b.ReliableSession.Ordered);
Console.WriteLine("Inactivity in Minutes: {0}",
b.ReliableSession.InactivityTimeout.TotalMinutes);
}
Private Sub Run()
Dim b As New WSHttpBinding()
b.Name = "HttpOrderedReliableSessionBinding"
' Get a reference to the OptionalreliableSession object of the
' binding and set its properties to new values.
Dim myReliableSession As OptionalReliableSession = b.ReliableSession
myReliableSession.Enabled = True ' The default is false.
myReliableSession.Ordered = False ' The default is true.
myReliableSession.InactivityTimeout = New TimeSpan(0, 15, 0)
' The default is 10 minutes.
' Create a URI for the service's base address.
Dim baseAddress As New Uri("http://localhost:8008/Calculator")
' Create a service host.
Dim sh As New ServiceHost(GetType(Calculator), baseAddress)
' Optional: Print out the binding information.
PrintBindingInfo(b)
' Create a URI for an endpoint, then add a service endpoint using the
' binding with the latered OptionalReliableSession settings.
sh.AddServiceEndpoint(GetType(ICalculator), b, "ReliableCalculator")
sh.Open()
Console.WriteLine("Listening...")
Console.ReadLine()
sh.Close()
End Sub
Private Sub PrintBindingInfo(ByVal b As WSHttpBinding)
Console.WriteLine(b.Name)
Console.WriteLine("Enabled: {0}", b.ReliableSession.Enabled)
Console.WriteLine("Ordered: {0}", b.ReliableSession.Ordered)
Console.WriteLine("Inactivity in Minutes: {0}", b.ReliableSession.InactivityTimeout.TotalMinutes)
End Sub
注解
启用可靠会话的功能由系统提供的三个绑定提供。 可靠的会话为:
可选(默认关闭)以及NetTcpBindingWSHttpBinding
必需 (因此始终打开) 与 WSDualHttpBinding。
构造函数
| 名称 | 说明 |
|---|---|
| OptionalReliableSession() |
初始化 OptionalReliableSession 类的新实例。 |
| OptionalReliableSession(ReliableSessionBindingElement) |
从可靠会话绑定元素初始化类的新实例 OptionalReliableSession 。 |
属性
| 名称 | 说明 |
|---|---|
| Enabled |
获取或设置一个值,该值指示是否启用可靠会话。 |
| InactivityTimeout |
获取或设置服务在关闭前可以保持非活动状态的时间间隔。 (继承自 ReliableSession) |
| Ordered |
获取或设置一个值,该值指示消息传递是否必须保留消息的发送顺序。 (继承自 ReliableSession) |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |