WCF concepts: bindings vs. behaviors

来源:互联网 发布:如何做好seo 编辑:程序博客网 时间:2024/06/05 09:56

 http://www.pluralsight-training.net/community/blogs/aaron/archive/2006/03/02/19470.aspx

 

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 servicesand endpoints.
 
A service exposes one or more endpoints. Each endpoint consists of anaddress,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 endpointon the wire. The WCF runtime uses the binding configuration to build the appropriatechannel stack for processing incoming/outgoing messages. The channel stack sits between the wire and thedispatcher(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 atransportchannel, a message encoder (the thing that translates the logical message into bytes), and a number of WS-*protocolchannels (for security, reliable messaging, etc). The binding is all about what happens on the wire. In essence, it's whatbindsmessages 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 callsbehaviors. 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:bindingsto configure wire-level agreement and behaviors to customize local execution.

 

原创粉丝点击