BindingElement.BuildChannelFactory<TChannel>(BindingContext) Method

Definition

初始化通道工厂,用于生成来自绑定上下文中指定类型的通道。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)

Type Parameters

TChannel

工厂生成的通道类型。The type of channel the factory builds.

Parameters

context
BindingContext

为绑定元素提供上下文的 BindingContextThe BindingContext that provides context for the binding element.

Returns

IChannelFactory<TChannel>

IChannelFactory<TChannel> 类型的 TChannel(从 context 中初始化)。The IChannelFactory<TChannel> of type TChannel initialized from the context.

Exceptions

contextnullcontext is null.

Examples

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();

Applies to