Appendix E. Generic Interceptor

At its core, WCF is nothing more than an extensibility model. All the built-in attributes, behaviors, and infrastructure are implemented using this open and public extensibility model. In theory, every developer has as much access and power as any member of the WCF team. As demonstrated throughout this book (with the exception of my security extensions), as long as you are familiar with the extensibility model, with a mere few lines of code you can inject powerful behavior and customization into your application. In practice, however, dealing with the interception mechanism requires intimate knowledge of the WCF architecture. To simplify matters, I wanted to provide an easy-to-use abstraction on top of the WCF extensibility model that would, in a way, extend the extensibility model itself, allowing for intercepting all calls to the service, both on the client and the service side, in a general manner, and adding custom behavior, without having to deal with the inner workings of WCF. This appendix presents a small framework I call the generic interceptor, available with ServiceModelEx. It also demonstrates some advanced WCF programming techniques, as well as the thought process behind designing such extensions.

Intercepting Service Operations

Recall from Chapter 1 that in the abstract, all WCF does when intercepting calls is perform pre- and post-call operations. Adding custom steps to this interception mechanism is probably the most common way ...

Get Programming WCF Services, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.