BindingElement.BuildChannelFactory<TChannel>(BindingContext) 方法

定義

初始化通道處理站,以便從繫結內容產生指定型別的通道。Initializes a channel factory for producing channels of a specified type from the binding context.

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

類型參數

TChannel

處理站建置之通道的型別。The type of channel the factory builds.

參數

context
BindingContext

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

傳回

IChannelFactory<TChannel> 型別的 TChannel,初始化自 contextThe IChannelFactory<TChannel> of type TChannel initialized from the context.

例外狀況

contextnullcontext is null.

範例

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

IChannelFactory<IRequestChannel> factory = element.BuildChannelFactory<IRequestChannel>(context);
factory.Open();
EndpointAddress address = new EndpointAddress("http://localhost:8000/ChannelApp");
IRequestChannel channel = factory.CreateChannel(address);
channel.Open();
Message request = Message.CreateMessage(MessageVersion.Default, "hello");
Message reply = channel.Request(request);
Console.Out.WriteLine(reply.Headers.Action);
reply.Close();
channel.Close();
factory.Close();

適用於