BindingElement.CanBuildChannelFactory<TChannel>(BindingContext) 方法

定義

傳回值,指出繫結項目是否可以建置 (Build) 特定通道類型的通道處理站。Returns a value that indicates whether the binding element can build a channel factory for a specific type of channel.

public:
generic <typename TChannel>
 virtual bool CanBuildChannelFactory(System::ServiceModel::Channels::BindingContext ^ context);
public virtual bool CanBuildChannelFactory<TChannel> (System.ServiceModel.Channels.BindingContext context);
abstract member CanBuildChannelFactory : System.ServiceModel.Channels.BindingContext -> bool
override this.CanBuildChannelFactory : System.ServiceModel.Channels.BindingContext -> bool
Public Overridable Function CanBuildChannelFactory(Of TChannel) (context As BindingContext) As Boolean

類型參數

TChannel

通道處理站所產生之通道的類型。The type of channel the channel factory produces.

參數

context
BindingContext

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

傳回

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

例外狀況

contextnullcontext is null.

範例

CustomBinding binding = new CustomBinding();
HttpTransportBindingElement element = new HttpTransportBindingElement();
BindingParameterCollection parameters = new BindingParameterCollection();
BindingContext context = new BindingContext(binding, parameters);

bool bFlag = element.CanBuildChannelFactory<IRequestChannel>(context);

備註

如果您要在嘗試建置處理站之前,先檢查是否可以針對提供的 TChannel 建置 context 型別之通道的通道處理站,請使用這個方法。Use this method if you want to check that the channel factory for channels of type TChannel can be build for the context provided before attempting to build the factory. 或者,請呼叫 BuildChannelFactory 來建置通道處理站並攔截產生的例外狀況 (如果無法建置的話)。Alternatively, build the channel factory by calling BuildChannelFactory and catch the exception generated if it cannot be built.

適用於