MSDN Magazine - December 2007 - (Page 103) Extending WCF with Custom Behaviors AARON SKONNARD W indows® Communication Foundation (WCF) provides numerous extensibility points that allow developers to customize the runtime behavior for service dispatching and client proxy invocation. You can tap into these extensibility points by writing custom behaviors that can be applied declaratively to your services. This month I’ll show you how this process works. WCF Extensibility In my last column I focused on the WCF concept of a binding, which you can specify for each endpoint on your WCF service. The binding controls the messaging details (what happens on the wire) for that endpoint. It’s essentially the recipe WCF follows to build a channel stack capable of transforming between a stream of bytes (the message on the wire) and a WCF message. There are countless extensibility points found throughout the WCF channel layer. WCF also provides a higher-level runtime that sits on top of the channel layer, targeted more at the application developer. It is often referred to throughout the WCF documentation as the service model layer. This higher-level runtime consists primarily of a component called the dispatcher (within the context of a service host) and a component called the proxy (within the context of a client). The dispatcher/proxy combination serves one primary purpose—to translate between WCF Message objects and Microsoft® .NET Framework method calls (see Figure 1). These components follow a well-defined sequence of steps to perform this process, and at each step along the way they provide extensibility points that you can plug into. You can use these extensiThe dispatcher/proxy bility points to implement components provide a wide variety of custom extensibility points behaviors including message or parameter valiyou can plug into to dation, message logging, implement a wide variety message transformations, of custom behaviors. custom serialization/deserialization formats, output caching, object pooling, error handling, and authorization, to name a few. Here I’ll focus on the implementation of these types of custom behaviors. Dispatcher/Proxy Extensions Both the dispatcher and proxy provide numerous extensibility points where you can inject your own code; these extensions are often referred to as interceptors because they allow you to intercept the default execution behavior of the runtime. However, I usually refer to them as runtime extensions. Figure 2 shows the client-side proxy architecture and the exten- Client Method Method Service Method Method Method Objects Parameter Inspection 1 ClientOperation Message Formatting 2 (serialization) Message Inspection 3 ClientRuntime Method Objects ClientOperation Objects Proxy Message Objects Dispatcher Message Message Protocol Protocol Protocol Protocol Encoder Encoder Transport Message Stream Transport Transport 0101101 Channel Stack Channel Stack Channel Stack Figure 1 WCF Runtime Architecture Figure 2 Proxy (Client) Extensions december2007 103
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.