Export (0) Print
Expand All

BindingElement Class

The elements of the bindings that build the channel factories and channel listeners for various types of channels that are used to process outgoing and incoming messages.

System.Object
  System.ServiceModel.Channels.BindingElement
    More...

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public abstract class BindingElement

The BindingElement type exposes the following members.

  NameDescription
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsBindingElement()Initializes a new instance of the BindingElement class.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsBindingElement(BindingElement)Initializes a new instance of the BindingElement class from a specified binding element.
Top

  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsBuildChannelFactory<TChannel>Initializes a channel factory for producing channels of a specified type from the binding context.
Public methodBuildChannelListener<TChannel>Initializes a channel listener to accept channels of a specified type from the binding context.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanBuildChannelFactory<TChannel>Returns a value that indicates whether the binding element can build a channel factory for a specific type of channel.
Public methodCanBuildChannelListener<TChannel>Returns a value that indicates whether the binding element can build a listener for a specific type of channel.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCloneWhen overridden in a derived class, returns a copy of the binding element object.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetProperty<T>When overridden in a derived class, returns a typed object requested, if present, from the appropriate layer in the binding stack.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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 are 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 requirement 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 sending 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 receiving 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.

NoteNote

  If you are adding message headers that must be encrypted you must return a ChannelProtectionRequirements instance with your requirements from the GetProperty<T>(BindingContext) method when asked for ChannelProtectionRequirements.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2014 Microsoft