BindingElement.BuildChannelFactory<TChannel>(BindingContext) Méthode

Définition

Initialise une fabrique de canal pour générer des canaux d’un type spécifié à partir du contexte de liaison.

C#
public virtual System.ServiceModel.Channels.IChannelFactory<TChannel> BuildChannelFactory<TChannel> (System.ServiceModel.Channels.BindingContext context);

Paramètres de type

TChannel

Type de canal construit par la fabrique.

Paramètres

context
BindingContext

BindingContext qui fournit le contexte pour l'élément de liaison.

Retours

IChannelFactory<TChannel> de type TChannel initialisé à partir de context.

Exceptions

context a la valeur null.

Exemples

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

S’applique à

Produit Versions
.NET Core 1.0, Core 1.1, 8
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
UWP 10.0