Tải bản đầy đủ (.pdf) (910 trang)

Programming WCF Services pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (13.29 MB, 910 trang )

www.it-ebooks.info
www.it-ebooks.info
Programming WCF Services
www.it-ebooks.info
www.it-ebooks.info
THIRD EDITION
Programming WCF Services
Juval Löwy
Beijing

Cambridge

Farnham

Köln

Sebastopol

Taipei

Tokyo
www.it-ebooks.info
Programming WCF Services, Third Edition
by Juval Löwy
Copyright © 2010 Juval Löwy. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly
books
may
be purchased for educational, business, or sales promotional use. Online editions


are also available for most titles (). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or
Editors: Mike Hendrickson and Laurel Ruma
Production Editor: Teresa Elsey
Proofreader: Teresa Elsey
Indexer: Newgen North America, Inc.
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
Printing History:
February 2007:
First Edition.
November 2008: Second Edition.
August 2010:
Third Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Programming WCF Services, Third Edition,
the image of an angelfish, and related
trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-0-596-80548-7
[M]
1281631550
www.it-ebooks.info
To my family

www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Preface .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
1. WCF Essentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What Is WCF? 1
Services 2
Service Execution Boundaries 3
WCF and Location Transparency 4
Addresses 4
TCP Addresses 5
HTTP Addresses 6
IPC Addresses 6
MSMQ Addresses 7
Service Bus Addresses 7
Contracts 7
The Service Contract 8
Hosting 11
IIS 5/6 Hosting 12
Self-Hosting 13
WAS Hosting 19
Custom Hosting in IIS/WAS 19
Windows Server AppFabric 20
Choosing a Host 22
Bindings 24
The Common Bindings 25
Choosing a Binding 26
Additional Bindings 27

Using a Binding 29
Endpoints 29
Administrative Endpoint Configuration 30
vii
www.it-ebooks.info
Programmatic Endpoint Configuration 34
Default Endpoints 36
Metadata Exchange 39
Metadata over HTTP-GET 39
The Metadata Exchange Endpoint 42
The Metadata Explorer 49
More on Behavior Configuration 51
Client-Side Programming 53
Generating the Proxy 53
Administrative Client Configuration 57
Programmatic Client Configuration 64
The WCF-Provided Test Client 64
Programmatic Versus Administrative Configuration 67
WCF Architecture 67
Host Architecture 69
Working with Channels 70
The InProcFactory Class 71
Transport-Level Sessions 75
Transport Session and Binding 76
Transport Session Termination 76
Reliability 77
Bindings, Reliability, and Ordered Messages 78
Configuring Reliability 79
Requiring Ordered Delivery 80
2. Service Contracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

Operation Overloading 83
Contract Inheritance 86
Client-Side Contract Hierarchy 87
Service Contract Factoring and Design 90
Contract Factoring 90
Factoring Metrics 93
Contract Queries 95
Programmatic Metadata Processing 95
The MetadataHelper Class 98
3. Data Contracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Serialization 103
.NET Serialization 105
The WCF Formatters 107
Data Contract via Serialization 110
Data Contract Attributes 111
Importing a Data Contract 113
viii | Table of Contents
www.it-ebooks.info
Data Contracts and the Serializable Attribute 116
Inferred Data Contracts 117
Composite Data Contracts 118
Data Contract Events 119
Shared Data Contracts 123
Data Contract Hierarchy 123
Known Types 124
Service Known Types 126
Multiple Known Types 128
Configuring Known Types 129
Data Contract Resolvers 129
Objects and Interfaces 141

Data Contract Equivalence 143
Serialization Order 144
Versioning 146
New Members 146
Missing Members 147
Versioning Round-Trip 151
Enumerations 154
Delegates and Data Contracts 155
Generics 156
Collections 160
Concrete Collections 160
Custom Collections 162
The CollectionDataContract Attribute 163
Referencing a Collection 164
Dictionaries 165
4. Instance Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Behaviors 169
Per-Call Services 171
Benefits of Per-Call Services 171
Configuring Per-Call Services 172
Per-Call Services and Transport Sessions 173
Designing Per-Call Services 174
Choosing Per-Call Services 177
Per-Session Services 177
Configuring Private Sessions 178
Sessions and Reliability 182
The Session ID 184
Session Termination 185
Singleton Service 185
Initializing a Singleton 187

Table of Contents | ix
www.it-ebooks.info
Choosing a Singleton 189
Demarcating Operations 190
Instance Deactivation 193
Configuring with ReleaseInstanceMode.None 194
Configuring with ReleaseInstanceMode.BeforeCall 194
Configuring with ReleaseInstanceMode.AfterCall 195
Configuring with ReleaseInstanceMode.BeforeAndAfterCall 196
Explicit Deactivation 197
Using Instance Deactivation 198
Durable Services 198
Durable Services and Instance Management Modes 199
Instance IDs and Durable Storage 199
Explicit Instance IDs 201
Instance IDs in Headers 203
Context Bindings for Instance IDs 205
Automatic Durable Behavior 210
Throttling 217
Configuring Throttling 219
5. Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Request-Reply Operations 225
One-Way Operations 226
Configuring One-Way Operations 226
One-Way Operations and Reliability 227
One-Way Operations and Sessionful Services 227
One-Way Operations and Exceptions 228
Callback Operations 230
The Callback Contract 231
Client Callback Setup 232

Service-Side Callback Invocation 235
Callback Connection Management 239
The Duplex Proxy and Type Safety 241
The Duplex Factory 244
Callback Contract Hierarchy 246
Events 247
Streaming 251
I/O Streams 251
Streaming and Binding 252
Streaming and Transport 253
6. Faults
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Error Isolation and Decoupling 255
Error Masking 256
x |
Table of Contents
www.it-ebooks.info
Channel Faulting 257
Fault Propagation 261
Fault Contracts 263
Fault Debugging 267
Faults and Callbacks 273
Error-Handling Extensions 276
Providing a Fault 277
Handling a Fault 280
Installing Error-Handling Extensions 282
The Host and Error Extensions 285
Callbacks and Error Extensions 289
7. Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
The Recovery Challenge 293

Transactions 294
Transactional Resources 295
Transaction Properties 295
Transaction Management 297
Resource Managers 301
Transaction Propagation 301
Transaction Flow and Bindings 301
Transaction Flow and the Operation Contract 302
One-Way Calls 304
Transaction Protocols and Managers 305
Protocols and Bindings 306
Transaction Managers 307
Transaction Manager Promotion 310
The Transaction Class 311
The Ambient Transaction 312
Local Versus Distributed Transactions 312
Transactional Service Programming 314
Setting the Ambient Transaction 314
Transaction Propagation Modes 316
Voting and Completion 324
Transaction Isolation 327
Transaction Timeout 329
Explicit Transaction Programming 331
The TransactionScope Class 331
Transaction Flow Management 333
Non-Service Clients 340
Service State Management 342
The Transaction Boundary 343
Instance Management and Transactions 343
Table of Contents | xi

www.it-ebooks.info
Per-Call Transactional Services 345
Per-Session Transactional Services 348
Transactional Durable Services 362
Transactional Behavior 365
Transactional Singleton Service 371
Instancing Modes and Transactions 374
Callbacks 375
Callback Transaction Modes 376
Callback Voting 378
Using Transactional Callbacks 378
8. Concurrency Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Instance Management and Concurrency 383
Service Concurrency Modes 384
ConcurrencyMode.Single 384
ConcurrencyMode.Multiple 385
ConcurrencyMode.Reentrant 389
Instances and Concurrent Access 392
Per-Call Services 392
Sessionful and Singleton Services 393
Resources and Services 393
Deadlocked Access 394
Deadlock Avoidance 395
Resource Synchronization Context 396
.NET Synchronization Contexts 397
The UI Synchronization Context 400
Service Synchronization Context 405
Hosting on the UI Thread 406
A Form as a Service 412
The UI Thread and Concurrency Management 415

Custom Service Synchronization Contexts 417
The Thread Pool Synchronizer 418
Thread Affinity 423
Priority Processing 425
Callbacks and Client Safety 429
Callbacks with ConcurrencyMode.Single 429
Callbacks with ConcurrencyMode.Multiple 430
Callbacks with ConcurrencyMode.Reentrant 431
Callbacks and Synchronization Contexts 431
Callbacks and the UI Synchronization Context 432
Callback Custom Synchronization Contexts 435
Asynchronous Calls 439
Requirements for an Asynchronous Mechanism 439
xii | Table of Contents
www.it-ebooks.info
Proxy-Based Asynchronous Calls 440
Asynchronous Invocation 442
Polling or Waiting for Completion 445
Completion Callbacks 447
One-Way Asynchronous Operations 452
Asynchronous Error Handling 456
Asynchronous Calls and Transactions 457
Synchronous Versus Asynchronous Calls 457
9. Queued Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Disconnected Services and Clients 461
Queued Calls 462
Queued Calls Architecture 463
Queued Contracts 463
Configuration and Setup 464
Transactions 471

Delivery and Playback 471
Service Transaction Configuration 473
Nontransactional Queues 476
Instance Management 477
Per-Call Queued Services 478
Sessionful Queued Services 480
Singleton Service 483
Concurrency Management 484
Throttling 485
Delivery Failures 485
The Dead-Letter Queue 487
Time to Live 487
Configuring the Dead-Letter Queue 488
Processing the Dead-Letter Queue 490
Playback Failures 494
Poison Messages 495
Poison Message Handling in MSMQ 4.0 495
Poison Message Handling in MSMQ 3.0 501
Queued Versus Connected Calls 501
Requiring Queuing 502
The Response Service 504
Designing a Response Service Contract 505
Client-Side Programming 509
Queued Service-Side Programming 512
Response Service-Side Programming 514
Transactions 514
The HTTP Bridge 518
Table of Contents | xiii
www.it-ebooks.info
Designing the Bridge 518

Transaction Configuration 519
Service-Side Configuration 520
Client-Side Configuration 522
10. Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Authentication 525
Authorization 526
Transfer Security 527
Transfer Security Modes 527
Transfer Security Mode Configuration 529
Transport Security and Credentials 532
Message Security and Credentials 533
Identity Management 533
Overall Policy 534
Scenario-Driven Approach 534
Intranet Application Scenario 535
Securing the Intranet Bindings 536
Constraining Message Protection 543
Authentication 544
Identities 547
The Security Call Context 548
Impersonation 550
Authorization 558
Identity Management 563
Callbacks 564
Internet Application Scenario 566
Securing the Internet Bindings 566
Message Protection 568
Authentication 572
Using Windows Credentials 574
Using the ASP.NET Providers 575

Identity Management 584
Business-to-Business Application Scenario 585
Securing the Business-to-Business Bindings 585
Authentication 586
Authorization 589
Identity Management 590
Host Security Configuration 591
Anonymous Application Scenario 591
Securing the Anonymous Bindings 591
Authentication 592
Authorization 592
xiv | Table of Contents
www.it-ebooks.info
Identity Management 592
Callbacks 593
No Security Scenario 593
Unsecuring the Bindings 593
Authentication 594
Authorization 594
Identity Management 594
Callbacks 594
Scenarios Summary 595
Declarative Security Framework 595
The SecurityBehaviorAttribute 596
Host-Side Declarative Security 604
Client-Side Declarative Security 605
Security Auditing 612
Configuring Security Audits 613
Declarative Security Auditing 615
11. The Service Bus . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
What Is a Relay Service? 618
The Windows Azure AppFabric Service Bus 619
Programming the Service Bus 620
Relay Service Address 620
The Service Bus Registry 623
The Service Bus Explorer 625
The Service Bus Bindings 626
The TCP Relay Binding 626
The WS 2007 Relay Binding 630
The One-Way Relay Binding 631
The Event Relay Binding 632
Cloud as Interceptor 633
Service Bus Buffers 634
Buffers Versus Queues 635
Working with Buffers 636
Sending and Retrieving Messages 642
Buffered Services 643
Response Service 652
Service Bus Authentication 657
Configuring Authentication 658
Shared Secret Authentication 659
No Authentication 663
Metadata over the Service Bus 665
Transfer Security 667
Transport Security 668
Table of Contents | xv
www.it-ebooks.info
Message Security 669
TCP Relay Binding and Transfer Security 670

WS Relay Binding and Transfer Security 676
One-Way Relay Binding and Transfer Security 676
Bindings and Transfer Modes 677
Streamlining Transfer Security 678
A. Introduction to Service Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
B. Headers and Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
C. Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
D. Publish-Subscribe Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 775
E. Generic Interceptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809
F. WCF Coding Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825
G. ServiceModelEx Catalog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855
xvi | Table of Contents
www.it-ebooks.info
Foreword
When Juval Löwy asked me to write the foreword for the first edition of this book, I
was working in a Community Program Manager role for the brand-new Windows
Communication Foundation (WCF) framework at Microsoft. WCF was the result of
a multiyear effort to write a unified communication framework for Windows. It was
also the result of a multiyear effort to create an interoperable messaging standards
framework centered around XML and the SOAP envelope model, with a common
model for addressing; a transport-independent abstraction for session management and
ordered delivery semantics; and a common model for message and session protection,
for federated authentication and authorization, and for many more capabilities. This
industry-wide standardization effort is still in progress with Microsoft and partners
across the industry, refining and updating this common messaging framework (sum-
marily nicknamed “WS-*”), more than 10 years after the SOAP 1.1 specification was
submitted as a note to W3C, which started this process.
As I write the foreword to the new edition, I’m filling an Architect role on the Windows
Azure AppFabric team at Microsoft. More precisely, I’m contributing to the architec-

ture of the service bus, a service offering that’s part of the Windows Azure Platform
and which Juval covers in Chapter 11 and the appendixes of this book. The way I
commonly describe the effort of building a commercial web services infrastructure, like
the service bus or its sibling service, Windows Azure AppFabric Access Control, is to
use the familiar iceberg analogy. The “above the water” features that the customers get
to interact with on the public protocol and API surface area make up a relatively small
portion of the overall effort. The rest, all the things beneath the waterline, quite closely
resembles a large-scale, mission-critical Enterprise application infrastructure—with the
special quality and challenge of running on a public cloud-based infrastructure.
When you create a Windows Azure account, your data and the provisioning jobs run
through WCF SOAP services. When you create a new service namespace in our system,
the messages flow between data centers using WCF SOAP services, creating resources
in the places where you ask for them to be created. Monitoring happens via WCF SOAP
services; diagnostics happens via WCF SOAP services; billing data collection, consol-
idation, and handoff happens using WCF SOAP services.
xvii
www.it-ebooks.info
As people providing a public web service infrastructure, we’re looking to provide
equally capable messaging-centric and REST protocol heads and resource projections
across the infrastructure. Because of concerns about broad reach into browsers and
devices, the prioritization often plays out in a way that the REST protocol heads for the
public protocol surface area win out and get built first—and mostly on top of the HTTP
web programming model provided by WCF. However, there has never been any serious
debate or question in cross-team engineering discussions about the interfaces between
the various subsystems under the waterline not being SOAP-based endpoints built on
WCF. Everyone already went into the room with the assumption that they would be.
Building the backbone systems for a cross-team effort at Microsoft with several hundred
engineers and an investment volume the size of the Windows Azure Platform is at or
beyond the complexity level of many mission-critical Enterprise systems. Running such
a system and upgrading or changing parts of such a system in flight and without down-

time is not only complex, it’s an art form. You need loose coupling between subsystems,
you need a lot of flexibility and extensibility, and you need to have a clear notion of
what that other system is going to accept and return in terms of messages. What I keep
finding is that once you confront a “simpler” communications model with real-world
requirements of the sort we’ve got on the Windows Azure backbone, you almost in-
evitably end up reinventing the wheel at the protocol level and you increasingly make
the life of implementers harder.
WCF is a great technology because it deals with the complexity of flexibly intercon-
necting applications. It’s great because you can build SOAP services, building the
backbone of your systems that can interoperate with other services on other platforms
with similarly capable web services stacks, such as those built by Oracle/Sun, IBM, or
the Apache Foundation. It’s great because it allows you to build the “broad-reach”
HTTP/REST resource projection surface of your system on the same foundation.
The book you have in your hands is rightfully “the book” about the Windows Com-
munication Foundation. Continuously improving our skills at architecting and build-
ing distributed business applications is a passion that Juval and I share.
This book is going to help you learn about the “distributed” part—how to hook stuff
together and how to do so securely, reliably, and in a loosely coupled fashion—all from
Juval Löwy, one of the most prominent distributed systems experts in the world today.
xviii | Foreword
www.it-ebooks.info
Programming WCF Services shows you in great detail what we here at Microsoft have
built as a foundation for your applications and services, and the book conveys it with
the accuracy, teaching skill, and dedication to architecture that Juval is justly renowned
for around the globe.
I’ll stop now. Turn the page. Start reading.
—Clemens Vasters
Principal Technical Lead,Windows Azure AppFabric Service Bus, Microsoft
Foreword | xix
www.it-ebooks.info

www.it-ebooks.info
Preface
In August 2001, I first learned the details of a Microsoft effort to rewrite COM+ using
managed code. Nothing much happened after that. Then, during a C# 2.0 Strategic
Design Review in July 2002, 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. At the time, there was no cohesive
programming model that unified these distinct technologies. Toward the end of 2003,
I was privileged to be invited to join a small team of outside industry experts and to
participate in the strategic design review of a new development platform codenamed
Indigo. Some of the smartest and nicest people I know were part of that team. Over the
next two to three years, Indigo went through some three generations of programming
models. The final declarative, endpoint-driven object model debuted in early 2005, was
stabilized by August of that year, and was named the Windows Communication Foun-
dation (WCF). WCF was released in November 2006 as part of .NET 3.0.
As I am writing these lines in late 2010, I find it hard to believe the past four years have
gone so quickly, and that I have a third edition of the book to correspond with the third
release of WCF and .NET 4.0.
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 host-
ing, that provide off-the-shelf plumbing for applications. To the application developer,
it is a declarative programming model for structuring applications. And to the architect,
it is a tool for building service-oriented applications. WCF is, in actuality, all of those,

simply because it was designed that way—to be the unified next generation of Micro-
soft’s disparate technologies.
xxi
www.it-ebooks.info
To me, WCF is the next development platform, which to a large extent subsumes
raw .NET programming. All .NET developers should use WCF, regardless of their
application types, sizes, or industry domains. 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 was engineered from the ground
up to simplify application development and deployment and to lower the overall cost
of ownership. WCF services allow you 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, illustrating how to take advantage of built-in features such
as service hosting, instance management, concurrency management, transactions, dis-
connected 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 pro-
gramming 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 engi-
neering 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 dis-
ruptive 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 cov-
erage to the possibilities and practical aspects of using WCF: how to apply the tech-
nology 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. Serv-
iceModelEx 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
xxii | Preface
www.it-ebooks.info
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 Mag-
azine, 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 inher-
itance, 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.
Preface | xxiii
www.it-ebooks.info

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×