WCF concepts: bindings vs. behaviors

The Windows Communication Foundation programming model and runtime provide a great framework for thinking about service-oriented systems. I love the way they’ve abstracted away unnecessary details through a suite of simple concepts that make it easier to think about these types of systems. The most central concepts are services and endpoints.
A service exposes one or more endpoints. Each endpoint consists of an address, binding, and contract. The contract is the main thing developers care about when designing the service code. You implement a service contract in a traditional .NET class (by simply implementing the C# interface). The address is simply the location where consumers send SOAP messages in order to integrate with the service. Most developers immediately “get” the address/contract concepts, but bindings often require more discussion.
The binding is the thing that influences the transport/message-level details of the endpoint. It’s all about “how” once interacts with the endpoint on the wire. The WCF runtime uses the binding configuration to build the appropriate channel stack for processing incoming/outgoing messages. The channel stack sits between the wire and the dispatcher (the thing that actually invokes your service code). Each channel in the stack is responsible for different aspects of messaging processing. There will always be a transport channel, a message encoder (the thing that translates the logical message into bytes), and a number of WS-* protocol channels (for security, reliable messaging, etc). The binding is all about what happens on the wire. In essence, it’s what binds messages coming off the wire to the WCF dispatcher.
So the dispatcher is the thing that manages the execution of your code. You can influence different aspects of local execution using what WCF calls behaviors. A behavior is just a piece of code that implements a special interface (one which the runtime knows about ahead of time) for “plugging into” the execution process. This is your primary WCF extensibility point. You configure behaviors with a service using .NET attributes or configuration elements. WCF ships a suite of built-in behaviors that address the most desired behavioral customizations. Behaviors are all about local execution — what happens within the local CLR host.
Bindings and behaviors are the two primary things you’ll configure in WCF systems: bindings to configure wire-level agreement and behaviors to customize local execution.
Copy from  Aaron Skonnard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s