How This Book Is Organized

This book covers the topics and skills you need to design and develop service-oriented WCF-based applications, illustrating how to take advantage of built-in features such as service hosting, instance management, concurrency management, transactions, disconnected queued calls, security, and the Windows Azure AppFabric Service Bus. While the book shows you how to use these features, it focuses on the “why” and on the rationale behind particular design decisions. You’ll learn about not only WCF programming and the related system issues, but also relevant design options, tips, best practices, and pitfalls. I approach 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 the insights this text provides, you can engineer your applications for maintainability, extensibility, reusability, and productivity.

This third edition has provided me with several opportunities: first, to catch up with WCF in .NET 4.0 with its new features such as hosting, discovery, and configuration. Second, I wanted to present the AppFabric Service Bus, which is a fundamentally disruptive technology because of the sort of applications it allows developers to build. Third, I have had two more years’ worth of WCF techniques, ideas, and helper classes, as well as improvement of the ideas I had in the first and second editions. I believe this new material will make this edition valuable even to readers of the second edition.

This book avoids many implementation details of WCF and largely confines its coverage to the possibilities and practical aspects of using WCF: how to apply the technology and how to choose among the available design and programming models. It makes the most of what .NET 4.0 and the service bus 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, collectively known as ServiceModelEx. My tools, helper classes, and attributes aim at increasing your productivity and the quality of your WCF services. ServiceModelEx is literally a small framework that sits on top of WCF and compensates for some oversights in its design. ServiceModelEx also 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. Many readers have told me that aside from the explanations in this book, ServiceModelEx is the most valuable asset the book offers. I have also kept to my guideline that, in principle, readers should not have to use all (or any part) of ServiceModelEx. In practice, ServiceModelEx is your WCF power tools collection. You can also use each helper class, utility, or framework individually, as there are few, if any, interdependencies.

During the past six years, I have published a number of WCF articles in MSDN Magazine, and I wrote 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, are wider in scope (offering additional angles, techniques, and samples) and up to date, and often tie their subjects into other chapters.

Each chapter addresses a single topic and discusses it in depth. However, the chapters often rely on those that precede them, so you should read the book in order.

Here is a brief summary of the chapters and appendixes in this book:

Chapter 1, WCF Essentials

This first chapter starts by explaining what WCF is, then describes essential WCF concepts and building blocks (such as addresses, contracts, bindings, endpoints, hosting, and clients) and key concepts such as reliability and transport sessions. The chapter includes a discussion of the WCF architecture, which is really the linchpin of all that follows in the subsequent chapters. This chapter assumes that 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 that you give this chapter at least a cursory reading, not only to ensure that you have a 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

Chapter 2 is dedicated to the topic of designing and working with service contracts. First, it covers some useful techniques for service contract overloading and inheritance, as well as some advanced techniques. The chapter also discusses how to design and factor contracts that cater to reuse, maintainability, and extensibility. It ends by showing you how to interact programmatically with the metadata of the exposed contracts at runtime.

Chapter 3, Data Contracts

Chapter 3 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. In this chapter, 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

This chapter answers the question of which service instance handles which client’s request. WCF supports several service instance management, activation, and lifetime management techniques, and your choices will have drastic implications for scalability, performance, the programming model, and the business workflow. This chapter presents the rationale behind each of the instance management modes, offers guidelines on when and how to best use them, and also addresses some related topics, such as durability and throttling.

Chapter 5, Operations

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

Chapter 6, Faults

This chapter discusses the best practices of error handling, enabling you to decouple the client’s error handling from the service’s. When required, the chapter shows 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. This chapter also demonstrates how you can extend and improve on WCF’s basic error-handling mechanism.

Chapter 7, Transactions

This chapter begins by explaining the motivation for transactions in general, 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

Chapter 8 first 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 of concurrency management, such as callbacks, reentrancy, thread affinity, and synchronization context, best practices and guidelines for avoiding deadlocks, and asynchronous call management.

Chapter 9, Queued Services

Chapter 9 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, 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. It also presents techniques for streamlining queues, call management, and several original design ideas (such as a queued response service).

Chapter 10, Security

This chapter demystifies service-oriented security by breaking down this multifaceted task into its basic elements, such as message transfer, authentication, and authorization. It also demonstrates how to provide security for key scenarios such as intranet and Internet applications. Finally, it presents my framework for declarative WCF security, designed to automate security setup and to considerably simplify managing security.

Chapter 11, The Service Bus

This chapter presents the Windows Azure AppFabric Service Bus. In my opinion, the service bus is the most important technology to come out of Microsoft in recent years. The service bus addresses the crucial connectivity issues of web services, and it offers advantages in scalability, availability, and security. I expect that, in the future, the service bus will be the predominant way of extending applications, even intranet applications. WCF is the programming model of the service bus, but there are many particular aspects, from security to buffering, that require special attention. The chapter presents the problems the service bus was designed to address, how to use the service bus as a relay service or as an events hub or as a buffer, and the related security model. You will also see many helper classes designed to streamline the programming model.

Appendix A

This appendix is designed for readers who want to understand what service orientation is all about: it presents my take on service orientation and puts 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. It then presents the principles of service orientation and augments the abstract tenets with a few more practical points required by most applications. In this appendix, I also share my perspective on where SOA and WCF are heading.

Appendix B

This appendix introduces two distinct techniques for enabling the client to pass out-of-band parameters to the service, resulting in a custom logical context: you will see how to use either the message headers or the context binding to achieve this goal. This appendix also presents my helper classes, which greatly simplify and encapsulate the required programming. These helper classes and custom contexts are used in several places in the book.

Appendix C

This appendix starts by describing the basic offering of service discovery and availability announcements introduced in .NET 4.0. Discovery simplifies service and client deployment and management, and allows for great volatility across time and deployment sites. The appendix then shows some simple techniques and helper classes you can use to streamline the programming model. The appendix ends with my technique for adding discovery to the service bus in a way that mimics regular WCF discovery, combining the power of discovery with the connectivity of the service bus.

Appendix D

Appendix D presents several techniques for implementing a publish-subscribe event management solution. It starts with my framework, which lets you develop a publishing and a subscription service in, at most, one line of code. The appendix then shows how to use the service bus for publish-subscribe and ends with a discovery-enabled publish-subscribe solution that requires no explicit subscription steps.

Appendix E

This appendix presents a general-purpose extensible framework for intercepting calls to your WCF services. It walks through the technique and thought process behind such an extension and shows two examples of how to utilize this simple yet powerful and useful technique.

Appendix F

Appendix F is basically a consolidated list of all the best practices and dos and don’ts mentioned throughout this book. The standard is all about the “how” and the “what,” not the “why.” The rationale behind it is found in the rest of the book. The standard also uses the terms and helper classes discussed in this book.

Appendix G

This final appendix presents a catalog of the 100 or so public helper types (excluding internal helper types) of ServiceModelEx mentioned in the book, arranged by categories and techniques, with a short description of each.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.33.157