カスタム バインディングを探索クライアント チャネルと共に使用する
カスタム バインディングを DiscoveryClientBindingElement と共に使用する場合は、DiscoveryEndpoint インスタンスを作成する DiscoveryEndpointProvider を定義する必要があります。
DiscoveryEndpointProvider の作成
DiscoveryEndpointProvider は、DiscoveryEndpoints を必要に応じて作成します。探索エンドポイント プロバイダーを定義するには、DiscoveryEndpointProvider からクラスを派生させ、GetDiscoveryEndpoint メソッドをオーバーライドし、新しい探索エンドポイントを返します。次の例は、探索エンドポイント プロバイダーを作成する方法を示しています。
// Extend DiscoveryEndpointProvider class to change the default DiscoveryEndpoint
// to the DiscoveryClientBindingElement. The Discovery ClientChannel
// uses this endpoint to send Probe message.
public class UdpDiscoveryEndpointProvider : DiscoveryEndpointProvider
{
public override DiscoveryEndpoint GetDiscoveryEndpoint()
{
return new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005);
}
}
探索エンドポイント プロバイダーを定義したら、次の例に示すように、カスタム バインディングを作成し、その探索エンドポイント プロバイダーを参照する DiscoveryClientBindingElement を追加できます。
DiscoveryClientBindingElement discoveryBindingElement = new DiscoveryClientBindingElement();
// Provide the search criteria and the endpoint over which the probe is sent.
discoveryBindingElement.FindCriteria = new FindCriteria(typeof(ICalculatorService));
discoveryBindingElement.DiscoveryEndpointProvider = new UdpDiscoveryEndpointProvider();
CustomBinding customBinding = new CustomBinding(new NetTcpBinding());
// Insert DiscoveryClientBindingElement at the top of the BindingElement stack.
// An exception is thrown if this binding element is not at the top.
customBinding.Elements.Insert(0, discoveryBindingElement);
探索クライアント チャネルの使用詳細情報、「探索クライアント チャネルの使用」を参照してください。コード例全体については、「探索バインディング要素のサンプル」を参照してください。