Preface


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 Organized

This 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:


Chapter 1, WCF Essentials

Starts by explaining what WCF is, and then describes essential WCF concepts and building blocks, such as addresses, contracts, bindings, endpoints, hosting, and clients. The chapter ends with a discussion of the WCF architecture, which is really the linchpin of all that is enabled in the subsequent chapters. This chapter assumes you understand the basic motivation and benefit of service-orientation. If that is not the case, you should first read Appendix A. Even if you are already familiar with the basic concepts of WCF, I recommend you give this chapter at least, cursory reading, not only to ensure you have the solid foundation but also because some of the helper classes and terms introduced here will be used and extended throughout the book.


Chapter 2, Service Contracts

Is dedicated to designing and working with service contracts. You will first learn some useful techniques for service contract overloading and inheritance, and some advanced techniques. The chapter next discusses how to design and factor contracts that cater to reuse, maintainability, and extensibility. The chapter ends by showing you how to interact programmatically at runtime with the metadata of the exposed contracts.


Chapter 3, Data Contracts

Deals with how the client and the service can exchange data without ever actually sharing the data type itself or using the same development technology. You will see how to deal with some interesting real-life issues such as data versioning, and how to pass collections of items.


Chapter 4, Instance Management

Is dedicated to answering which service instance handles which client's request. WCF supports several service instance management, activation, and lifetime management techniques with drastic implications on scalability and performance. This chapter provides the rationale for each of the instance management modes, offers guidelines on when and how to best use them, and also addresses some related topics, such as throttling.


Chapter 5, Operations

Deals with the types of operations clients can invoke on a service and the related design guidelines, such as how to improve and extend the basic offering to support callback setup and teardown, manage callback ports and channels, and provide for type-safe duplex proxies.


Chapter 6, Faults

Is all about how services can report errors and exceptions back to their clients, since constructs such as exceptions and exception handling are technology-specific and should not transcend the service boundary. The chapter discusses the best practices of error handling, enabling you to decouple the client error handling from the service. The chapter also demonstrates how you can extend and improve on the basic error-handling mechanism.


Chapter 7, Transactions

Begins by providing the motivation for transactions in general, and then discusses the many aspects of transactional services: the transaction management architecture, transaction propagation configuration, the declarative transaction support offered by WCF, and how clients can create transactions. The chapter ends by discussing relevant design guidelines such as transactional service state management and instancing modes.


Chapter 8, Concurrency Management

Describes the powerful yet simple declarative way WCF offers for managing concurrency and synchronization, both for the client and the service. The chapter then presents more advanced aspects such as callbacks, reentrancy, thread affinity, and synchronization context and best practices and guidelines for avoiding deadlocks.


Chapter 9, Queued Services

Shows how clients can queue up calls to services, thus enabling asynchronous, disconnected work. The chapter starts by showing how to set up and configure queued services, and then focuses on aspects such as transactions, instance management, and failures and their impact on both the business model of the service and its implementation.


Chapter 10, Security

Demystifies service-oriented security by breaking down this multifaceted task into its basic elements, such as message transfer, authentication, and authorization. The chapter continues to demonstrate how to provide security for key scenarios such as intranet and Internet applications. Finally, you will see my framework for declarative WCF security, designed to automate security setup and to considerably simplify managing security.


Appendix A, Introduction to Service-Orientation

Is designed for readers who want to understand what service-orientation is all about. This appendix presents my take on service-orientation and what it means to put it in a concrete context. The appendix defines service-oriented applications (as opposed to mere architecture) and the services themselves, and examines the benefits of the methodology. The appendix then presents the principles of service-orientation and augments the abstract tenets with a few more practical points required by most applications.


Appendix B, Publish-Subscribe Service

Presents my framework for implementing a publish-subscribe event management solution. The framework lets you develop a publishing and a subscription service in literally one or two lines of code. While the publish-subscribe pattern could have just as well been part of Chapter 5, it is in a dedicated appendix because it utilizes aspects described in other chapters, such as transactions and queued calls.


Appendix C, WCF Coding Standard

Is basically a consolidated list of all the best practices and dos and don'ts mentioned throughout the book. The standard is all about the "how" and the "what," not the "why." The rationale behind the standard is found in the rest of the book. The standard also uses the helper classes discussed in this book.

Some Assumptions About the Reader

I 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 Book

To 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 Book

The following typographic conventions are used in this book:


Italic

Used for technical terms, online links, and filenames


Constant width

Used for code samples, statements, namespaces, classes, assemblies, interface directives, operators, attributes, and reserved words


Constant width bold

Used for code emphasis

This icon designates a note, which is an important aside to the nearby text.


This icon designates a warning relating to the nearby text.


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 Examples

This 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 Us

Please address comments and questions concerning this book to the publisher:

O'Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international/local)
707-829-0104 (fax)

There is a web page for this book, which lists errata, examples, or any additional information. You can access this page at:

http://www.oreilly.com/catalog/0596526997

To comment or ask technical questions about this book, send email to:

bookquestions@oreilly.com

You can also contact the author at:

http://www.idesign.net

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® Enabled

When 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.

Acknowledgments

I 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.




Programming WCF Services
Programming WCF Services
ISBN: 0596526997
EAN: 2147483647
Year: 2004
Pages: 148
Authors: Juval Lowy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net