In August 2001 I first learned the details of an effort in Microsoft to rewrite COM+ using managed code. Nothing much happened after that. Then, in July 2002, during a C# 2.0 Strategic Design Review, the remoting program manager outlined in broad strokes plans to rework remoting into something that developers should actually use. At the same time, Microsoft was also working on incorporating the new security specs for web services into the ASMX stack and actively working with others on drafting a score of additional web services specs. In July 2003 I was given access to a new transactional infrastructure that improved on the deficiencies in transactional .NET programming. As of yet, there was no cohesive programming model that unified these distinct technologies. Towards the end of 2003 I was privileged to be invited to join a small team of outside industry experts and participate in the strategic design review of a new development platform code- named Indigo. Some of the smartest and nicest people I know were part of that team. Over the next 23 years Indigo went through some three generations of programming models. The current declarative, endpoint-driven object model debuted in early 2005, was stabilized by August of that year, and was named the Windows Communication Foundation (WCF). It is difficult to get a consistent answer from different people on what WCF is. To the web service developer, it is the ultimate interoperability solution, an implementation of a long list of industry standards. To the distributed application developer, it is the easiest way of making remote calls and even queued calls. To the system developer, it is the next generation of productivity-oriented features, such as transactions and hosting, that provide off-the-shelf plumbing for applications. To the application developer, it is a declarative programming model for structuring the application. And to the architect, it is how one can finally build service-oriented applications. WCF is in actuality all of those, simply because it was designed that wayto be the unified next generation of Microsoft's disparate technologies. To me, WCF is simply the next development platform, which to a large extent subsumes raw .NET programming. WCF should be used by any .NET developer, regardless of the application type, size, or industry domain. WCF is a fundamental technology that provides an easy and clean way to generate services and applications in compliance with what I regard as sound design principles. WCF is engineered from the ground up to simplify application development and deployment, and to lower the overall cost of ownership. WCF services are used to build service-oriented applications, from standalone desktop applications to web-based applications and services to high-end Enterprise applications. How This Book Is OrganizedThis book covers the topics and skills you need to design and develop service-oriented WCF-based applications. You will see how to take advantage of built-in features such as service hosting, instance management, concurrency management, transactions, disconnected queued calls, and security. While the book shows you how to use these features, it sets the focus on the "why" and the rationale behind particular design decisions. You'll not only learn WCF programming and the related system issues, but also relevant design options, tips, best practices, and pitfalls. I approached almost every topic and aspect from a software engineering standpoint because my objective is to make you not just a WCF expert, but also a better software engineer. Armed with such insights, you can engineer your application for maintainability, extensibility, reusability, and productivity. The book avoids many implementation details of WCF and largely confines its coverage to the possibilities and the practical aspects of using WCF: how to apply the technology and how to choose among the available design and programming models. The book makes the most of what .NET 2.0 has to offer, and in some respects is an advanced C# book as well. In addition, the book contains many useful utilities, tools, and helper classes I have written. My tools and helper classes or attributes aim at increasing your productivity and the quality of your WCF services. I literally developed a small framework that sits on top of WCF and compensates for some oversights in its design or simplifies and automates certain tasks. This book is as much about my tools, ideas, and techniques as it is about native WCF, and my framework also demonstrates how you can extend WCF. During the past two years I have published a number of WCF articles in MSDN Magazine, and I presently write the WCF section of the Foundations column for the magazine as well. I used these articles to seed the chapters in this book, and I am grateful to the magazine for allowing me to do so. Even if you have read the articles, you should still read the corresponding chapters here. The chapters are much more comprehensive, offering additional angles, techniques, and samples, and often tie their subjects to other chapters. Each chapter systematically addresses a single topic and discusses it in depth. However, each chapter does rely on the ones that precede it, so you should read the chapters in order. Here is a brief summary of the chapters and appendixes in this book:
Some Assumptions About the ReaderI assume you, the reader, are an experienced developer and that you are comfortable with object-oriented concepts such as encapsulation and inheritance. I will take advantage of your existing understanding of object and component technology and terminology, and port that knowledge to WCF. You should ideally have a fair understanding of .NET and know basic C# 2.0 (including use of generics and anonymous methods). Although the book uses C# for the most part, it is just as pertinent to Visual Basic 2005 developers. What You Need to Use This BookTo use this book, you will need .NET 2.0, Visual Studio 2005, the released components of .NET 3.0, along with the .NET 3.0 development SDK and the .NET 3.0 extensions for Visual Studio 2005. Unless explicitly mentioned, the book applies to Windows XP, Windows Server 2003, and Windows Vista. You may also install additional Windows components, such as MSMQ and IIS. Conventions Used in This BookThe following typographic conventions are used in this book:
Whenever I wish to make a point in a code sample, I do so with the static Assert method of the Debug class: int number = 1+2; Debug.Assert(number == 3); The Assert method accepts a Boolean statement, and throws an exception when the statement is false. The book follows the recommended naming guidelines and coding style presented in Appendix E of my book Programming .NET Components (O'Reilly). Whenever it deviates from that standard it is likely the result of space or line length constraints. As for naming conventions, I use "Pascal casing" for public member methods and properties; this means the first letter of each word in the name is capitalized. For local variables and method parameters I use "camel casing," in which the first letter of the first word of the name is not capitalized. In the case of private members, I prefix such variables with m_: public class SomeClass { int m_Number; public int Number {get;set}; } I use ellipses between curly braces to indicate the presence of code that is necessary but unspecified: public class SomeClass {...} In the interest of clarity and space, code examples often do not contain all the using statements needed to specify all the namespaces the example requires; instead, such examples include only the new namespaces introduced in the preceding text. Using Code ExamplesThis book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from this book does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product's documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Programming WCF Services by Juval Löwy. Copyright 2007 O'Reilly Media, Inc., 978-0-596-52699-3." If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. How to Contact UsPlease address comments and questions concerning this book to the publisher:
There is a web page for this book, which lists errata, examples, or any additional information. You can access this page at:
To comment or ask technical questions about this book, send email to:
You can also contact the author at:
The author has posted a comprehensive code library on the IDesign web site with more than 120 downloads on WCF essentials, contract design, instance management, operations and calls, faults, transactions, concurrency, queuing, and security. The downloads articulate in a working fashion many of the code snippets in this book. Safari® EnabledWhen you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O'Reilly Network Safari Bookshelf. Safari offers a solution that's better than e-books. It's a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com. AcknowledgmentsI would not have been able to come to terms with WCF in its early days without the constant support and interaction with the WCF (then Indigo) program managers. I am especially grateful to my friend Steve Swartz, one of the WCF architects, not just for his knowledge and insight, but also for his patience with me, and those long IM sessions. Thanks go to Yasser Shohoud, Doug Purdy, and Shy Cohen for the fascinating strategic design reviews, and to Krish Srinivasan for his almost philosophical approach to engineering. Working with you guys has been the best part of learning WCF and a privilege on its own right. The following WCF program managers also shared their time and helped clarify WCF: Andy Milligan, Brian McNamara, Eugene Osovetsky, Kenny Wolf, Kirill Gavrylyuk, Max Feingold, Michael Marucheck, Mike Vernal, and Steve Millet. Thanks also to the group manager, Angela Mills. Outside Microsoft, thanks to Norman Headlam and Pedro Felix for providing valuable feedback. I am grateful to Nicholas Paldino for his help. Nick's knowledge of the .NET framework is second to none, and his meticulous attention to details contributed greatly to the quality and cohesiveness of this book. Finally, to my family: my wife, Dana, who keeps encouraging me to write down my ideas and techniques, while knowing too well that writing a book entails precious time away from the her and the girls; and to my parents, who imparted to me the love for engineering. I dedicate this book to my seven-year-old daughter, Abigail, and my four-year-old, Eleanor. You all mean the world to me. |