OptionalReliableSession 類別

定義

提供一個方便的方式,不管選擇性可靠工作階段是否已啟用,都能在使用其中一個預先定義的繫結時進行存取。

public ref class OptionalReliableSession : System::ServiceModel::ReliableSession
public class OptionalReliableSession : System.ServiceModel.ReliableSession
type OptionalReliableSession = class
    inherit ReliableSession
Public Class OptionalReliableSession
Inherits ReliableSession
繼承
OptionalReliableSession

範例

下列範例示範如何建立新的可靠工作階段,然後存取並變更該工作階段的預設值。

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

備註

啟用可靠工作階段的功能,由三種系統提供的繫結所提供。 可靠工作階段有︰

建構函式

OptionalReliableSession()

初始化 OptionalReliableSession 類別的新執行個體。

OptionalReliableSession(ReliableSessionBindingElement)

從可靠工作階段繫結項目,初始化 OptionalReliableSession 類別的新執行個體。

屬性

Enabled

取得或設定值,這個值表示可靠工作階段是否已啟用。

InactivityTimeout

取得或設定服務在關閉之前維持在非作用狀態的時間間隔。

(繼承來源 ReliableSession)
Ordered

取得或設定值,這個值會指出訊息傳遞是否必須保留訊息傳送時的順序。

(繼承來源 ReliableSession)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於