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);
Discovery 클라이언트 채널 사용에 대한 자세한 내용은 Discovery 클라이언트 채널 사용을 참조하십시오. 전체 코드 예제를 보려면 Discovery Binding Element 샘플를 참조하십시오.