CustomBinding Class

Defines a binding from a list of binding elements.

System.Object
  System.ServiceModel.Channels.Binding
    System.ServiceModel.Channels.CustomBinding

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)
[ContentPropertyAttribute("Elements")]
public class CustomBinding : Binding

The CustomBinding type exposes the following members.

  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCustomBinding()Initializes a new instance of the CustomBinding class.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCustomBinding(Binding)Initializes a new instance of the CustomBinding class from the values of a specified binding.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCustomBinding(BindingElement[])Initializes a new instance of the CustomBinding class from an array of binding elements.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCustomBinding(IEnumerable<BindingElement>)Initializes a new instance of the CustomBinding class with the binding elements from a complete channel stack.
Public methodCustomBinding(String)Initializes a new instance of the CustomBinding class.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCustomBinding(String, String, BindingElement[])Initializes a new instance of the CustomBinding class from an array of binding elements with a specified name and namespace.
Top
  NameDescription
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsCloseTimeoutGets or sets the interval of time provided for a connection to close before the transport raises an exception. (Inherited from Binding.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsElementsGets the binding elements from the custom binding.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsMessageVersionGets the message version used by clients and services configured with the binding. (Inherited from Binding.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsNameGets or sets the name of the binding. (Inherited from Binding.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsNamespaceGets or sets the XML namespace of the binding. (Inherited from Binding.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsOpenTimeoutGets or sets the interval of time provided for a connection to open before the transport raises an exception. (Inherited from Binding.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsReceiveTimeoutGets or sets the interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped. (Inherited from Binding.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsSchemeGets the URI scheme for transport used by the custom binding. (Overrides Binding.Scheme.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsSendTimeoutGets or sets the interval of time provided for a write operation to complete before the transport raises an exception. (Inherited from Binding.)
Top
  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsBuildChannelFactory<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. (Inherited from Binding.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsBuildChannelFactory<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. (Inherited from Binding.)
Public methodBuildChannelListener<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. (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Object[])Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified. (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, Object[])Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified. (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, BindingParameterCollection)Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified. (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, String, Object[])Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified. (Inherited from Binding.)
Public methodBuildChannelListener<TChannel>(Uri, String, BindingParameterCollection)Builds the channel listener on the service that accepts a specified type of channel and that satisfies the features specified. (Inherited from Binding.)
Public methodBuildChannelListener<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. (Inherited from Binding.)
Public methodBuildChannelListener<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. (Inherited from Binding.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanBuildChannelFactory<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. (Inherited from Binding.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanBuildChannelFactory<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. (Inherited from Binding.)
Public methodCanBuildChannelListener<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. (Inherited from Binding.)
Public methodCanBuildChannelListener<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. (Inherited from Binding.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreateBindingElementsReturns a generic collection of the binding elements from the custom binding. (Overrides Binding.CreateBindingElements().)
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>Returns a typed object requested, if present, from the appropriate layer in the binding stack. (Inherited from Binding.)
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 methodShouldSerializeNameReturns whether the name of the binding should be serialized. (Inherited from Binding.)
Public methodShouldSerializeNamespaceReturns whether the namespace of the binding should be serialized. (Inherited from Binding.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Use a custom binding when one of the system-provided bindings does not meet the requirements of your service. A custom binding could be used, for example, to enable the use of a new transport or a new encoder at a service endpoint.

A custom binding is constructed using one of the CustomBinding from a collection of binding elements that are "stacked" in a specific order:

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, flavors of MSMQ, Custom

Yes

In addition, you can define your own binding elements and insert them between any of the preceding defined layers.

For a discussion on how to use a custom binding to modify a system-provided binding, see How to: Customize a System-Provided Binding.

NoteNote

When calling a WCF service built with.Net Framework 4.0 from a WCF client application built with .NET Framework 3.5 or earlier, the configuration file generated by svcutil.exe or adding a service reference from Visual Studio will contain the validity attribute in the binding configuration. This attribute is not recognized by the .NET Framework 3.5 runtime and the application will thrown an ConfigurationErrorsException with the message "Unrecognized attribute validity". To workaround this problem, remove the validity attribute from the binding configuration.

The following example shows how to create a CustomBinding object using a ReliableSessionBindingElement and an HttpTransportBindingElement

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

// Create a ServiceHost for the CalculatorService type and provide the base address. 
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))
{
    // Create a custom binding that contains two binding elements.
    ReliableSessionBindingElement reliableSession = new ReliableSessionBindingElement();
    reliableSession.Ordered = true;

    HttpTransportBindingElement httpTransport = new HttpTransportBindingElement();
    httpTransport.AuthenticationScheme = System.Net.AuthenticationSchemes.Anonymous;
    httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

    CustomBinding binding = new CustomBinding(reliableSession, httpTransport);

    // Add an endpoint using that binding.
    serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, "");

    // Add a MEX endpoint.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.HttpGetUrl = new Uri("http://localhost:8001/servicemodelsamples");
    serviceHost.Description.Behaviors.Add(smb);

    // 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.5.1, 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 8, Silverlight 8.1

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. All rights reserved.