BindingElement.CanBuildChannelListener<TChannel>(BindingContext) 方法

定义

返回一个值,该值指示绑定元素是否可以为特定类型的通道生成侦听器。

public:
generic <typename TChannel>
 where TChannel : class, System::ServiceModel::Channels::IChannel virtual bool CanBuildChannelListener(System::ServiceModel::Channels::BindingContext ^ context);
public virtual bool CanBuildChannelListener<TChannel> (System.ServiceModel.Channels.BindingContext context) where TChannel : class, System.ServiceModel.Channels.IChannel;
abstract member CanBuildChannelListener : System.ServiceModel.Channels.BindingContext -> bool (requires 'Channel : null and 'Channel :> System.ServiceModel.Channels.IChannel)
override this.CanBuildChannelListener : System.ServiceModel.Channels.BindingContext -> bool (requires 'Channel : null and 'Channel :> System.ServiceModel.Channels.IChannel)
Public Overridable Function CanBuildChannelListener(Of TChannel As {Class, IChannel}) (context As BindingContext) As Boolean

类型参数

TChannel

侦听器接受的通道类型。

参数

context
BindingContext

为绑定元素提供上下文的 BindingContext

返回

如果绑定元素可以生成类型为 trueIChannelListener<TChannel>,则为 IChannel;否则为 false

例外

contextnull

示例

CustomBinding binding = new CustomBinding();
HttpTransportBindingElement element = new HttpTransportBindingElement();
BindingParameterCollection parameters = new BindingParameterCollection();
Uri baseAddress = new Uri("http://localhost:8000/ChannelApp");
String relAddress = "http://localhost:8000/ChannelApp/service";
BindingContext context = new BindingContext(binding, parameters, baseAddress, relAddress, ListenUriMode.Explicit);

bool bFlag = element.CanBuildChannelListener<IReplyChannel>(context);

注解

如果要在生成侦听器之前检查是否可以为提供的 TChannel 生成 context 类型通道的通道侦听器,请使用此方法。 或者,通过调用 BuildChannelListener 来生成通道侦听器,并捕捉无法生成时所产生的异常。

适用于