BindingElement.CanBuildChannelListener<TChannel>(BindingContext) 方法

定義

傳回值,指出繫結項目是否可以建置特定通道型別的通道接聽程式。Returns a value that indicates whether the binding element can build a listener for a specific type of channel.

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

接聽項接受的通道類型。The type of channel the listener accepts.

參數

context
BindingContext

BindingContext,其提供繫結項目的內容。The BindingContext that provides context for the binding element.

傳回

如果繫結項目可以建置 true 型別的 IChannelListener<TChannel>,則為 IChannel,否則為 falsetrue if the IChannelListener<TChannel> of type IChannel can be built by the binding element; otherwise, false.

例外狀況

contextnullcontext is null.

範例

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 型別之通道的通道接聽項,請使用這個方法。Use this method if you want to check that the channel listener for channels of type TChannel can be build for the context provided before attempting to build the listener. 或者,請呼叫 BuildChannelListener 來建置通道接聽程式並攔截產生的例外狀況 (如果無法建置的話)。Alternatively, build the channel listener by calling BuildChannelListener and catch the exception generated if it cannot be built.

適用於