BindingElement, classe
Assembly : System.ServiceModel (dans system.servicemodel.dll)
A binding consists of an ordered set of binding elements that inherit from this abstract base class. The TransportBindingElement class inherits from the BindingElement class.
Creating a binding and binding element for your transport is optional if you're just using the channel model. It is possible to do everything you need through the channel factory and listener as long as they are made public.
The Windows Communication Foundation (WCF) service model uses a factory pattern where the binding is used to create the channel stack. If you want to use the WCF service model, then using a transport binding element is required. Placing this binding element into a binding is a good practice because it removes the need for users to create their own custom binding for your transport. It is best to create both a binding and binding element, and hide the channel factory and listener inside the assembly.
On the send side, a binding is used to build a IChannelFactory which in turn builds a channel stack and returns a reference to the top channel in the stack. The application can then use this channel to send messages.
Similarly, on the receive side a binding is used to build a IChannelListener which listens for incoming messages. The IChannelListener provides messages to the listening application by creating channel stacks and handing the application a reference to the top channel. The application then uses this channel to receive incoming messages.
The following example shows how to add a transport binding element to a custom binding and then build a channel listener that can accept incoming messages.
CustomBinding binding = new CustomBinding(); binding.Elements.Add(new HttpTransportBindingElement()); BindingParameterCollection paramCollection = new BindingParameterCollection(); IChannelListener<IReplyChannel> listener = binding.BuildChannelListener<IReplyChannel> (new Uri("http://localhost:8000/ChannelApp"), paramCollection); listener.Open(); IReplyChannel channel = listener.AcceptChannel(); Console.WriteLine("Listening for messages"); channel.Open(); RequestContext request = channel.ReceiveRequest(); Message msg = request.RequestMessage; Console.WriteLine("Message Received"); Console.WriteLine("Message Action: {0}", msg.Headers.Action); if (msg.Headers.Action == "hello") { Message reply = Message.CreateMessage(MessageVersion.Default, "wcf"); request.Reply(reply); } msg.Close(); channel.Close(); listener.Close();
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Microsoft .NET Framework 3.0 est pris en charge sur Windows Vista, Microsoft Windows XP SP2 et Windows Server 2003 SP1.