This topic has not yet been rated - Rate this topic

Binding Class

Contains the binding elements that specify the protocols, transports, and message encoders used for communication between clients and services.

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
public abstract class Binding : IDefaultCommunicationTimeouts

The Binding type exposes the following members.

  Name Description
Protected method Supported by Portable Class Library Binding() Initializes a new instance of the Binding class with a default name and namespace.
Protected method Supported by Portable Class Library Binding(String, String) Initializes a new instance of the Binding class from a specified binding of the service.
Top
  Name Description
Public property Supported by Portable Class Library CloseTimeout Gets or sets the interval of time provided for a connection to close before the transport raises an exception.
Public property Supported by Portable Class Library MessageVersion Gets the message version used by clients and services configured with the binding.
Public property Supported by Portable Class Library Name Gets or sets the name of the binding.
Public property Supported by Portable Class Library Namespace Gets or sets the XML namespace of the binding.
Public property Supported by Portable Class Library OpenTimeout Gets or sets the interval of time provided for a connection to open before the transport raises an exception.
Public property Supported by Portable Class Library ReceiveTimeout Gets or sets the interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped.
Public property Supported by Portable Class Library Scheme When implemented in a derived class, sets the URI scheme that specifies the transport used by the channel and listener factories that are built by the bindings.
Public property Supported by Portable Class Library SendTimeout Gets or sets the interval of time provided for a write operation to complete before the transport raises an exception.
Top
  Name Description
Public method Supported by Portable Class Library BuildChannelFactory<TChannel>(BindingParameterCollection) Builds the channel factory stack on the client that creates a specified type of channel and that satisfies the features specified by a collection of binding parameters.
Public method Supported by Portable Class Library BuildChannelFactory<TChannel>(Object[]) Builds the channel factory stack on the client that creates a specified type of channel and that satisfies the features specified by an object array.
Public method BuildChannelListener<TChannel>(BindingParameterCollection) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified by a collection of binding parameters.
Public method BuildChannelListener<TChannel>(Object[]) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.
Public method BuildChannelListener<TChannel>(Uri, Object[]) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.
Public method BuildChannelListener<TChannel>(Uri, BindingParameterCollection) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.
Public method BuildChannelListener<TChannel>(Uri, String, Object[]) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.
Public method BuildChannelListener<TChannel>(Uri, String, BindingParameterCollection) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.
Public method BuildChannelListener<TChannel>(Uri, String, ListenUriMode, Object[]) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.
Public method BuildChannelListener<TChannel>(Uri, String, ListenUriMode, BindingParameterCollection) Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified.
Public method Supported by Portable Class Library CanBuildChannelFactory<TChannel>(BindingParameterCollection) Returns a value that indicates whether the current binding can build a channel factory stack on the client that satisfies the collection of binding parameters specified.
Public method Supported by Portable Class Library CanBuildChannelFactory<TChannel>(Object[]) Returns a value that indicates whether the current binding can build a channel factory stack on the client that satisfies the requirements specified by an object array.
Public method CanBuildChannelListener<TChannel>(BindingParameterCollection) Returns a value that indicates whether the current binding can build a channel listener stack on the service that satisfies the collection of binding parameters specified.
Public method CanBuildChannelListener<TChannel>(Object[]) Returns a value that indicates whether the current binding can build a channel listener stack on the service that satisfies the criteria specified in an array of objects.
Public method Supported by Portable Class Library CreateBindingElements When overridden in a derived class, creates a collection that contains the binding elements that are part of the current binding.
Public method Supported by Portable Class Library Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by Portable Class Library Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by Portable Class Library GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Supported by Portable Class Library GetProperty<T> Returns a typed object requested, if present, from the appropriate layer in the binding stack.
Public method Supported by Portable Class Library GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Supported by Portable Class Library MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ShouldSerializeName Returns whether the name of the binding should be serialized.
Public method ShouldSerializeNamespace Returns whether the namespace of the binding should be serialized.
Public method Supported by Portable Class Library ToString Returns a string that represents the current object. (Inherited from Object.)
Top

Represents a collection of binding elements, each of which describes an aspect of how an endpoint communicates with other endpoints and that are built, consistently, into a channel factory on the client and into a channel listener on the service. A binding contains a collection of binding elements that correspond to protocol channels, transport channels, and message encoders. There can be any number of binding elements for protocol channels but one and only one binding element for each the transport and message encoder. There are commonly six layers of binding elements in a binding. Only the transport and encoding binding elements at the bottom of the stack are required. Because an encoding is required for each binding, if an encoding is not specified, adds a default encoding for you. The default is Text/XML for the HTTP and HTTPS transports, and Binary for other transports.

The following table summarizes the options for each layer.

Layer

Options

Required

Transaction Flow

TransactionFlowBindingElement

No

Reliability

ReliableSessionBindingElement

No

Security

Symmetric, Asymmetric, Transport-Level

No

Shape Change

CompositeDuplexBindingElement

No

Transport Upgrades

SSL stream, Windows stream, Peer Resolver

No

Encoding

Text, Binary, MTOM, Custom

Yes

Transport

TCP, Named Pipes, HTTP, HTTPS, MSMQ, Custom

Yes

Each binding element provides the specification for building a channel factory on the client and a channel listener on the service. When the channel factory stack is constructed, for example, there is one channel factory in the stack for each binding element in the binding. The same sort of mapping applies to the channel listeners in the stack on the service. Consistency on the client and service is critical for establishing the channel-based connection between these endpoints. Each factory and listener, in turn, processes the sending and accepting of the corresponding channels in the channel stack that connects them, and these channels can then send and receive the messages used to communicate.

Each instance of a Binding has a Name and Namespace that together uniquely identify it in the metadata of the service. If no name or namespace is specified, adds a default values for you. The default name is null and the default namespace is http://tempuri.org/. This user name for the binding is distinct from the specification of the protocol name, which is specified by the Scheme property. If you want to add more HTTP bindings, for example, you can name them whatever you want and set all of their schemes to "http". There is no inherent application or machine dispatch based on the Scheme. So you avoid the common problem of being unable to register additional handlers for well-known protocols. You can also easily work with multiple versions of a binding side-by-side by giving each version a different name.

The Binding class implements the IDefaultCommunicationTimeouts interface to mitigate Denial of Service (DOS) attacks that rely on tying up resources for extended intervals of time. The implementation specifies the communication timeouts values for opening and closing connections and for the reading and writing operations associated with receiving and sending messages. The properties used to get and set these timeouts and their default values operations are summarized in the following table.

Timeout Property

Default Value

OpenTimeout

1 minute

CloseTimeout

1 minute

SendTimeout

1 minute

ReceiveTimeout

10 minutes

When you create a binding by inheriting from Binding, you must override CreateBindingElements.

In addition, you can define your own binding elements and insert them between any of the defined layers in the preceding table. For more information, see the CustomBinding class.


BasicHttpBinding binding = new BasicHttpBinding();

binding.Name = "binding1";

Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");
Uri address = new Uri("http://localhost:8000/servicemodelsamples/service/calc");

// Create a ServiceHost for the CalculatorService type and provide the base address.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, address);

    // Open the ServiceHostBase to create listeners and start listening for messages.
    serviceHost.Open();

    // The service can now be accessed.
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <ENTER> to terminate service.");
    Console.WriteLine();
    Console.ReadLine();
    // Close the ServiceHostBase to shutdown the service.
    serviceHost.Close();
}


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Create binding in web.config file
Hi all

i need help.

I'm trying tocreateuniontagsin myweb.config, butclient applications do notgetthe correctsettingsdefined byme.for example

this is my binding tag:
<wsHttpBinding  >
        <binding name="WSHttpBinding_svcValidarTelefono" closeTimeout="01:50:00"
           openTimeout="00:15:00" receiveTimeout="00:30:00" sendTimeout="02:10:00"
           allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
           maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
           messageEncoding="Text" textEncoding="utf-8"  useDefaultWebProxy="false">
          <reliableSession ordered="true"     inactivityTimeout="00:39:00"  enabled="true" />
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384123" maxBytesPerRead="4096" maxNameTableCharCount="16384123" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </wsHttpBinding>

but client applications to get this from my wef.config, use default values for timeout options

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_svcValidarTelefono" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:39:00" enabled="true" />
      <security mode="None">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

how I can make client applications using the settings defined in the tag wsHttpBinding and not using the default configuration.?

Thank

Roberto