How Bindings Work

Every service endpoint is associated with a particular binding. A binding is a runtime type that derives from the common base type Binding. Bindings describe the transport protocol, message-encoding format and other messaging protocols for the communication channel. In this section, I’m going to introduce you to each of the standard bindings, explain the features provided by the service model for bindings, and explain how binding configuration builds the communication channel.

Standard Bindings

In Chapter 1, I showed you how to configure an endpoint and its associated binding in two ways:

  • Declaratively, using service model configuration settings

  • Programmatically, by adding endpoints to the ServiceHost

Declaratively, you set the binding property for each service or client <endpoint> by referring to it by its configuration name, as shown here:

// service endpoint
<endpoint address="HelloIndigoService"binding="basicHttpBinding"
contract="Host.IHelloIndigoService" />

// client endpoint
<endpoint address="http://localhost:8000/HelloIndigo/HelloIndigoService"
binding="basicHttpBinding" contract="Client.localhost.IHelloIndigoService" />

Programmatically, you construct a binding instance and associate it with endpoints added to the ServiceHost or client proxy. In either case, you create an instance of the desired binding by its CLR type, for example:

BasicHttpBinding basicBinding = new BasicHttpBinding(  );
NetTcpBinding tcpBinding = new NetTcpBinding(  );

Each binding is represented ...

Get Learning WCF now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.