Steve Resnick, Richard Crane, Chris Bowen0-321-44006-4, 978-0-321-44006-8
В –Nicholas Allen, Program Manager, Web Services, Microsoft
В
Windows Communication Foundation (WCF) is the easiest way to produce and consume Web services on the Microsoft platform. With .NET 3.5, WCF has been extensively revamped–and Visual Studio 2008 gives developers powerful new tools for utilizing it. Essential Windows Communication Foundation shows developers exactly how to make the most of WCF with .NET 3.5 and Visual Studio 2008.
В
Drawing on extensive experience working with early adopters, three Microsoft insiders systematically address the topics developers ask about WCF. The authors approach each subject with practical advice and present best practices, tips, and tricks for solving problems. Throughout, you’ll find detailed explanations, solutions for the “pain points” of WCF development, and an extensive collection of reusable code examples. Coverage includes
Using WCF contracts to define complex structures and interfaces Understanding WCF’s channel stacks and channel model architecture Configuring the WCF communication stack to use only the protocols you need Using standard and custom service behaviors to manage concurrency, instances, transactions, and more Serializing data from .NET types to XML Infosets and representing Infosets “on the wire” Hosting WCF services via IIS, managed .NET applications, and Windows Activation Services WCF security, in depth: authentication; transport and message-level security; and Internet and intranet scenarios Improving reliability: exception handling, diagnostics, and more Workflow services: new integration points between WCF 3.5 and Windows Workflow Foundation Building client-to-client, peer network-based applications Utilizing WCF for non-SOAP Web services: AJAX and JSON examples and .NET 3.5 hosting classes Microsoft’s Steve Resnick, Richard Crane, and Chris Bowen are technology experts at the Microsoft Technology Center in Boston. They specialize in helping customers improve their technical agility by applying WCF and related technologies. Resnick has specialized in Internet technologies and distributed computing at Microsoft since 1995. He is a frequent speaker at Microsoft events and is now technology director for the U.S. Microsoft Technology Centers. Crane has more than 15 years of experience in senior software development roles. He specializes in large-scale Web sites, distributed computing, transactional systems, and performance analysis. Bowen has been an architect and developer for more than 15 years at companies such as Monster.com and Staples and is co-author of Professional Visual Studio 2005 Team System.
В
Foreword xxv
Preface xxvii
Chapter 1: Basics 1
Chapter 2: Contracts 33
Chapter 3: Channels 91
Chapter 4: Bindings 111
Chapter 5: Behaviors 181
Chapter 6: Serialization and Encoding 241
Chapter 7: Hosting 287
Chapter 8: Security 315
Chapter 9: Diagnostics 375
Chapter 10: Exception Handling 403
Chapter 11: Workflow Services 423
Chapter 12: Peer Networking 459
Chapter 13: Programmable Web 503
Appendix: Advanced Topics 537
Index 553
Table of contents :
Praise for Essential Windows Communication Foundation……Page 1
Microsoft .NET Development Series……Page 4
Copyright
……Page 6
Contents……Page 9
Figures……Page 19
Tables……Page 23
Foreword……Page 25
Preface……Page 27
Acknowledgments……Page 33
About the Authors……Page 35
Why WCF Matters……Page 37
Introduction……Page 39
Implementing a WCF Service……Page 42
Writing a WCF Service Entirely in Code……Page 43
Writing a Service with Code and Configuration Files……Page 46
More on Configuration Files……Page 48
More on Service Hosting……Page 49
Exposing the Metadata Exchange (MEX) Endpoint……Page 50
Writing a WCF Client Entirely in Code……Page 54
Writing a Client with Code and Configuration……Page 55
Discussion……Page 59
Hosting a Service in IIS in Three Steps……Page 60
Tools Support……Page 63
Generating Client Proxy Class and Configuration Files……Page 64
2 Contracts……Page 69
Service Contracts……Page 73
Synchronous Request-Response Operations……Page 74
Asynchronous Request-Response Operations……Page 77
One-Way Operations……Page 80
Duplex Operations……Page 82
Multiple Contracts and Endpoints in a Service……Page 90
Names of Operations, Types, Actions, and Namespaces in WSDL……Page 93
Data Contracts……Page 96
Defining XML Schema for a .NET Class……Page 98
Defining Class Hierarchies……Page 101
Exposing Additional Types in WSDL with KnownTypes……Page 103
Versioning Data Contracts……Page 108
Data Contract Equivalence……Page 111
Working with Collections……Page 112
Message Contracts……Page 114
Typed Messages……Page 115
Untyped Messages……Page 118
Using SOAP Headers with Untyped Messages……Page 121
3 Channels……Page 127
One-Way Communication Pattern……Page 130
Duplex Communication……Page 131
Request-Reply Communication……Page 133
Shape Changing……Page 134
Operation Contract and Channel Shapes……Page 135
Channel Listeners……Page 137
Channel Factories……Page 138
ChannelFactory……Page 140
ICommunicationObject……Page 141
4 Bindings……Page 147
Choosing an Appropriate Binding……Page 152
Sample Application……Page 155
netTcpBinding……Page 159
Local Machine Communication Between .NET Applications……Page 163
netNamedPipeBinding……Page 164
Communication Using Basic Web Services……Page 167
basicHttpBinding……Page 168
Communication Using Advanced Web Services……Page 171
wsHttpBinding……Page 173
ws2007HttpBinding……Page 176
wsDualHttpBinding……Page 179
Comparing Binding Performance and Scalability……Page 188
Communication Using Queued Services……Page 190
netMsmqBinding……Page 191
msmqIntegrationBinding……Page 201
Creating a Custom Binding……Page 204
Binding Elements……Page 207
Transports……Page 208
Encoders……Page 209
Security……Page 210
Transport Upgrades/Helpers……Page 211
Shape Change……Page 212
Exposing a Service Contract over Multiple Bindings……Page 213
5 Behaviors……Page 217
Concurrency and Instancing (Service Behavior)……Page 220
Default Concurrency and Instancing with Sessionless Binding……Page 223
Multithreading a Single Instance……Page 225
Implementing a Singleton……Page 226
Session-Level Instances……Page 229
Controlling the Number of Concurrent Instances……Page 231
Controlling the Number of Concurrent Calls……Page 235
Controlling the Number of Concurrent Sessions……Page 237
Exporting and Publishing Metadata (Service Behavior)……Page 240
Implementing Transactions (Operation Behavior)……Page 243
Transactional Operations Within a Service……Page 244
Flowing Transactions Across Operations……Page 251
Choosing a Transaction Protocol—OleTx or WS-AT……Page 257
Transaction Service Behaviors……Page 259
Implementing Custom Behaviors……Page 260
Implementing a Message Inspector for Service Endpoint Behavior……Page 263
Exposing a Parameter Inspector for Service Operation Behavior as an Attribute……Page 266
Exposing a Service Behavior Through Configuration……Page 269
Security Behaviors……Page 273
Serialization Versus Encoding……Page 277
DataContractSerializer……Page 279
NetDataContractSerializer……Page 283
XmlSerializer……Page 285
DataContractJsonSerializer……Page 288
Preserving References and Cyclical References……Page 290
Sharing Type with the NetDataContractSerializer……Page 296
Roundtrip Serialization Using IExtensibleDataObject……Page 300
Serializing Types Using Surrogates……Page 306
Streaming Large Data……Page 312
Using the XmlSerializer for Custom Serialization……Page 313
Custom XmlSerialization Using Attributes……Page 314
Custom XmlSerialization Using IXmlSerializable……Page 315
Choosing an Encoder……Page 317
Text Versus Binary Encoding……Page 318
Sending Binary Data Using MTOM Encoding……Page 319
Getting to Know the WebMessageEncoder……Page 320
7 Hosting……Page 323
Hosting a Service in Windows Process Activation Services……Page 324
Hosting a Service in IIS 7……Page 328
Enabling ASMX Features in an IIS-Hosted Service……Page 330
Self-Hosting……Page 337
Self-Hosting in a Managed Windows Service……Page 338
Hosting Multiple Services in One Process……Page 341
Defining Service and Endpoint Addresses……Page 344
8 Security……Page 351
Authorization……Page 352
Transport and Message Security……Page 353
Concepts……Page 355
Setup……Page 356
Transport-Level Security……Page 358
Encryption Using SSL……Page 359
Client Authentication……Page 363
Service Identity……Page 368
Message-Level Security……Page 370
Authenticating with wsHttpBinding……Page 371
Securing Services with Windows Integrated Security……Page 376
Section Examples Introduction……Page 377
Authenticating Users with Windows Credentials……Page 379
Authorizing Users with Windows Credentials……Page 382
Authorization Using AzMan……Page 384
Impersonating Users……Page 389
Securing Services over the Internet……Page 394
ASP.NET Integration……Page 396
Authentication Using Membership Providers……Page 397
Role-Based Authorization Using Role Providers……Page 400
Using Forms Authentication……Page 402
Logging and Auditing……Page 407
9 Diagnostics……Page 411
Tracing……Page 412
End-to-End Tracing……Page 413
Activities and Correlation……Page 414
Enabling Tracing……Page 415
Enabling Message Logging……Page 417
Additional Configuration Options……Page 419
Message Filters……Page 420
Trace Source Auto Flushing……Page 421
Performance Counters……Page 422
Using the Service Configuration Editor……Page 423
Logging Options……Page 425
Configuring Sources……Page 426
Configuring Listeners……Page 427
Activity View……Page 429
Graph View……Page 431
Analyzing Logs from Multiple Sources……Page 433
Filtering Results……Page 436
10 Exception Handling……Page 439
WCF Exception Communication via SOAP……Page 440
Unhandled Exception Example……Page 441
Detecting and Recovering a Faulted Channel……Page 444
Communicating Exception Details……Page 445
Managing Service Exceptions with FaultException……Page 447
Using FaultCode and FaultReason to Extend FaultException……Page 448
Limitations of Basic FaultExceptions……Page 450
Declaring Fault Definitions with FaultContract……Page 451
Defining a FaultContract……Page 453
Throwing a FaultException with a Defined FaultContract……Page 454
Implementing Client Fault Handlers……Page 455
Error-Handling Application Block……Page 456
Exception Shielding……Page 457
11 Workflow Services……Page 459
Integration Points……Page 460
Calling a WCF Service from WF……Page 462
Using a Send Activity……Page 463
Writing a Custom Activity……Page 466
Exposing a Service from WF……Page 469
Define the Interface……Page 470
Receive Activity……Page 471
Configuration in app.config……Page 475
Hosting a Service-Enabled Workflow……Page 477
Self-Hosting a Service-Enabled Workflow……Page 478
Hosting a Service-Enabled Workflow in IIS……Page 479
Correlation and Durable Services……Page 480
Long-Running Workflow……Page 481
Handling the Context……Page 486
Persisting Workflow State on the Server……Page 488
Controlling Access to Service-Enabled Workflows……Page 490
Programmatic Access Control……Page 491
Approaches to Building Distributed Applications……Page 495
N-Tier Applications……Page 496
Peer-to-Peer Applications……Page 497
Mesh Networks……Page 498
Message Flooding Versus Directional Messaging……Page 500
netPeerTcpBinding……Page 501
Resolving Peers Using PNRP……Page 504
Windows Internet Computer Names……Page 505
PnrpPeerResolver……Page 506
Registering Names Using PNRP……Page 507
System.Net.Peer……Page 508
Implementing a Custom Peer Resolver……Page 510
Limiting the Number of Hops for a Message……Page 514
Collaboration Using Windows Vista……Page 516
People Near Me……Page 517
Windows Contacts……Page 518
Invitations……Page 519
System.Net.PeerToPeer.Collaboration……Page 521
Directional Messaging Using Custom Binding……Page 528
13 Programmable Web……Page 539
All About the URI……Page 540
The Ubiquitous GET……Page 542
Web Programming with WCF……Page 543
URI and UriTemplates……Page 544
Building URIs……Page 545
Parsing URIs……Page 546
Creating Operations for the Web……Page 547
Hosting Using WebHttpBinding……Page 548
WebInvoke……Page 550
ASP.NET AJAX Integration……Page 552
Using the WebOperationContext……Page 559
WebScriptServiceHostFactory……Page 566
Content Syndication with RSS and ATOM……Page 567
Publishing Metadata Endpoints……Page 573
mexTcpBinding……Page 574
Creating Clients from Metadata……Page 575
Creating Silverlight Clients from Metadata……Page 577
Sharing Ports Between Services……Page 578
Configuring Service Quota Settings……Page 579
Configuring HTTP Connections……Page 581
Adjusting Connection Lifetime……Page 582
Disabling HTTP Keep-Alives……Page 583
Recycling Idle Connections……Page 585
Exposing LINQ-to-SQL Entities……Page 586
A……Page 589
B……Page 590
C……Page 591
D……Page 592
E……Page 593
G–H……Page 594
M……Page 595
O……Page 596
Q–R……Page 597
S……Page 598
T……Page 600
V–W……Page 601
X–Z……Page 602
Microsoft .NET Development Series……Page 603
Reviews
There are no reviews yet.