語言

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那就為綁定元素提供了背景。

傳回

true若 型IChannelListener<TChannel>IChannel態可由綁定元素構成;否則, false。

例外狀況

context 是 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 頻道監聽器,再嘗試建立監聽器,請使用此方法。 或者,透過呼叫 BuildChannelListener 來建立通道監聽器,若無法建立例外,則捕捉該異常。

適用於