Microsoft Docs

Windows Communication Foundation (WCF) Bindings

This tutorial introduces the most commonly used bindings in WCF for the .NET Framework 3.5.

Overview
Code Samples
Custom Binding

What is a Binding?

A binding defines how a service endpoint communicates with clients. It specifies the transport protocol, encoding, security, and other settings.

Standard Bindings

BasicHttpBinding

Provides interoperability with legacy ASMX web services. Uses HTTP transport and Text/XML encoding.

Learn more →

WSHttpBinding

Supports WS-* specifications, message security, and reliable sessions. Uses HTTP or HTTPS transport.

Learn more →

NetTcpBinding

Optimized for communication between .NET applications on the same intranet. Uses TCP transport.

Learn more →

NetNamedPipeBinding

High-performance binding for on-machine communication using named pipes.

Learn more →

NetMsmqBinding

Enables queued messaging using Microsoft Message Queuing (MSMQ).

Learn more →

Configuring Bindings in Code

// BasicHttpBinding example
var binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.None;

var address = new EndpointAddress("http://localhost:8080/Service");
var client = new MyServiceClient(binding, address);
client.Open();

Configuring Bindings in app.config

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="SecureBinding">
                <security mode="Transport">
                    <transport clientCredentialType="None" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>

    <client>
        <endpoint address="https://localhost:8443/Service"
                  binding="basicHttpBinding"
                  bindingConfiguration="SecureBinding"
                  contract="IService" />
    </client>
</system.serviceModel>

Creating a Custom Binding

Custom bindings let you combine transport, encoding, and protocol elements to meet specific requirements.

// CustomBinding example with TLS and binary encoding
var transport = new HttpsTransportBindingElement();
var encoding = new BinaryMessageEncodingBindingElement();
var security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();

var customBinding = new CustomBinding(security, encoding, transport);
var endpoint = new EndpointAddress("https://securehost:443/Service");
var client = new MyServiceClient(customBinding, endpoint);
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "pwd";
client.Open();

For a step‑by‑step guide, see Custom Binding Tutorial.