CustomBinding 類別

定義

從繫結項目的清單定義繫結。

public ref class CustomBinding : System::ServiceModel::Channels::Binding
public class CustomBinding : System.ServiceModel.Channels.Binding
[System.Windows.Markup.ContentProperty("Elements")]
public class CustomBinding : System.ServiceModel.Channels.Binding
type CustomBinding = class
    inherit Binding
[<System.Windows.Markup.ContentProperty("Elements")>]
type CustomBinding = class
    inherit Binding
Public Class CustomBinding
Inherits Binding
繼承
CustomBinding
屬性

範例

下列範例會示範如何使用 CustomBindingReliableSessionBindingElement 來建立 HttpTransportBindingElement 物件

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

備註

當系統提供的其中一個繫結程序不符合服務的需求時,請使用自訂繫結程序。 例如,若要在服務端點上啟用新的傳輸或新的編碼器,可以使用自訂繫結。

在建構自訂繫結時,會使用依據特定順序堆疊之繫結項目集合中的其中一個 CustomBinding

下表摘要列出每一層的選項。

選項。 必要
異動流程 TransactionFlowBindingElement
可靠性 ReliableSessionBindingElement
安全性 對稱、不對稱、傳輸層級
形狀變更 CompositeDuplexBindingElement
傳輸升級 SSL 資料流、Windows 資料流、對等解析程式
編碼 文字、二進位、MTOM、自訂
傳輸 TCP、具名管道、HTTP、HTTPS、MSMQ 的類別、自訂

此外,您也可以定義自己的繫結項目,並將其插入上述任何定義層之間。

如需如何使用自訂系結來修改系統提供的系結的討論,請參閱 如何:自訂System-Provided系結

注意

從以 .NET Framework 3.5 或更早版本建置的 WCF 用戶端應用程式呼叫以 .NET Framework 4.0 或更新版本建置的 WCF 服務時,svcutil.exe或從 Visual Studio 新增服務參考所產生的組態檔,將會包含系結組態中的有效屬性。 .NET Framework 3.5 執行時間無法辨識這個屬性,而且應用程式會擲回 ,並出現 ConfigurationErrorsException 「無法辨識的屬性有效性」訊息。 若要解決這個問題,請移除繫結組態中的 validity 屬性。

建構函式

CustomBinding()

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

CustomBinding(Binding)

從指定之繫結的值,初始化 CustomBinding 類別的新執行個體。

CustomBinding(BindingElement[])

從繫結項目的陣列初始化 CustomBinding 類別的新執行個體。

CustomBinding(IEnumerable<BindingElement>)

使用完整通道堆疊中的繫結項目,初始化 CustomBinding 類別的新執行個體。

CustomBinding(String)

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

CustomBinding(String, String, BindingElement[])

從具有指定之名稱和命名空間的繫結項目陣列,初始化 CustomBinding 類別的新執行個體。

屬性

CloseTimeout

取得或設定針對連線所提供的時間間隔 (此連線要在傳輸引發例外狀況之前關閉)。

(繼承來源 Binding)
Elements

從自訂繫結取得繫結項目。

MessageVersion

取得用戶端所使用的訊息版本及使用繫結所設定的服務。

(繼承來源 Binding)
Name

取得或設定繫結的名稱。

(繼承來源 Binding)
Namespace

取得或設定繫結的 XML 命名空間。

(繼承來源 Binding)
OpenTimeout

取得或設定針對連線所提供的時間間隔 (此連線要在傳輸引發例外狀況之前開啟)。

(繼承來源 Binding)
ReceiveTimeout

取得或設定連線中斷之前,可以維持非作用狀態的時間間隔 (在此期間未接收應用程式訊息)。

(繼承來源 Binding)
Scheme

取得自訂繫結所使用之傳輸的 URI 配置。

SendTimeout

取得或設定針對寫入作業所提供的時間間隔 (此作業要在傳輸引發例外狀況之前完成)。

(繼承來源 Binding)

方法

BuildChannelFactory<TChannel>(BindingParameterCollection)

在用戶端上建置通道處理站堆疊,此堆疊會建立指定的通道型別,並滿足繫結參數集合所指定的功能。

(繼承來源 Binding)
BuildChannelFactory<TChannel>(Object[])

在用戶端上建置通道處理站堆疊,此堆疊會建立指定的通道型別,並滿足物件陣列所指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式會接受指定的通道型別,並滿足繫結參數集合所指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection)

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
BuildChannelListener<TChannel>(Uri, String, Object[])

在服務上建置通道接聽程式,此接聽程式可接受指定的通道型別並滿足指定的功能。

(繼承來源 Binding)
CanBuildChannelFactory<TChannel>(BindingParameterCollection)

傳回值,這個值指出目前的繫結是否可以在用戶端上建置滿足指定之繫結參數集合的通道處理站堆疊。

(繼承來源 Binding)
CanBuildChannelFactory<TChannel>(Object[])

傳回值,這個值指出目前的繫結程序是否可以在用戶端上建置滿足物件陣列指定之需求的通道處理站堆疊。

(繼承來源 Binding)
CanBuildChannelListener<TChannel>(BindingParameterCollection)

傳回值,這個值指出目前的繫結是否可以在服務上建置滿足指定之繫結參數集合的通道接聽程式堆疊。

(繼承來源 Binding)
CanBuildChannelListener<TChannel>(Object[])

傳回值,這個值指出目前的繫結是否可以在服務上建置滿足物件陣列中指定之準則的通道接聽程式堆疊。

(繼承來源 Binding)
CreateBindingElements()

從自訂繫結傳回繫結項目的一般集合。

Equals(Object)

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

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetProperty<T>(BindingParameterCollection)

從繫結堆疊的適當層次中,傳回要求的型別物件 (如果有)。

(繼承來源 Binding)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ShouldSerializeName()

傳回繫結的名稱是否應該序列化。

(繼承來源 Binding)
ShouldSerializeNamespace()

傳回繫結的命名空間是否應該序列化。

(繼承來源 Binding)
ToString()

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

(繼承來源 Object)

適用於