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 いいえ
Reliability ReliableSessionBindingElement いいえ
セキュリティ 対称、非対称、Transport-Level いいえ
図形の変更 CompositeDuplexBindingElement いいえ
トランスポートのアップグレード SSL ストリーム、Windows ストリーム、ピア リゾルバー いいえ
Encoding Text、Binary、MTOM、Custom はい
Transport TCP、名前付きパイプ、HTTP、HTTPS、MSMQ のフレーバー、カスタム はい

さらに、独自のバインド要素を定義し、上記の定義済みのレイヤーの間に挿入することもできます。

カスタム バインドを使用してシステム提供のバインドを変更する方法については、「 方法: System-Provided バインドをカスタマイズする」を参照してください。

Note

.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, String, BindingElement[])

指定した名前と名前空間を持つバインド要素の配列から、 CustomBinding クラスの新しいインスタンスを初期化します。

CustomBinding(String)

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)

適用対象