
01_089842 ffirs.qxp 3/5/07 7:00 PM Page iii Professional WCF Programming .NET Development with the Windows® Communication Foundation Scott Klein 01_089842 ffirs.qxp 3/5/07 7:00 PM Page ii 01_089842 ffirs.qxp 3/5/07 7:00 PM Page i Professional WCF Programming 01_089842 ffirs.qxp 3/5/07 7:00 PM Page ii 01_089842 ffirs.qxp 3/5/07 7:00 PM Page iii Professional WCF Programming .NET Development with the Windows® Communication Foundation Scott Klein 01_089842 ffirs.qxp 3/5/07 7:00 PM Page iv Professional WCF Programming: .NET Development with the Windows® Communication Foundation Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-08984-2 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data: Klein, Scott, 1966- Professional WCF programming: .NET development with the Windows communication foundation / Scott Klein. p. cm. Includes index. ISBN 978-0-470-08984-2 (paper/website) 1. Application software--Development. 2. Microsoft Windows (Computer file) 3. Microsoft .NET. 4. Web services. I. Title. QA76.76.A65K6 2007 005.3--dc22 2007003318 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESEN- TATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WAR- RANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFES- SIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HERE- FROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOM- MENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade- marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Microsoft and Windows are registered trademarks of Microsoft Corpo- ration in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. 01_089842 ffirs.qxp 3/5/07 7:00 PM Page v About the Author Scott Klein is an independent consultant with passions for all things SQL Server, .NET, and XML. He is the author of Professional SQL Server 2005 XML by Wrox, writes the bi-weekly feature article for the SQL PASS Community Connector, and has contributed articles to both Wrox (www.Wrox.com) and TopXML (www.TopXML.com). He frequently speaks at SQL Server and .NET user groups. When he is not sitting in front of a computer or spending time with his family he can usually be found aboard his Yamaha at the local motocross track. He can be reached at [email protected]. 01_089842 ffirs.qxp 3/5/07 7:00 PM Page vi Credits Senior Acquisitions Editor Project Coordinator Jim Minatel Jennifer Theriot Development Editor Graphics and Production Specialists Howard A. Jones Denny Hager Jennifer Mayberry Technical Editor Alicia B. South William G. Ryan Quality Control Technicians Production Editor Cynthia Fields Eric Charbonneau John Greenough Copy Editor Proofreading and Indexing Kim Cofer Aptara Editorial Manager Anniversary Logo Design Mary Beth Wakefield Richard Pacifico Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Joseph B. Wikert 02_089842 ftoc.qxp 3/5/07 7:00 PM Page vii Contents Acknowledgments xiii Introduction xv Part I: Introduction to Windows Communication Foundation 1 Chapter 1: Windows Communication Foundation Overview 3 The Need for SOA 4 A Look Back 5 Understanding Service Orientation 6 Service-Oriented Architecture Principles 7 Microsoft’s Commitment to SOA 8 SOA Wrap-up 9 Why Windows Communication Foundation 9 WCF Architecture 10 The Makeup of WCF 13 WCF Features 15 Summary 16 Chapter 2: Windows Communication Foundation Concepts 17 Messages 18 Message Structure 18 Messaging Programs 23 Messaging Patterns 26 Channels 28 Channel Stacks 29 Services 30 Endpoint 33 Addresses 33 Bindings 33 Contracts 34 Behaviors 36 Summary 36 02_089842 ftoc.qxp 3/5/07 7:00 PM Page viii Contents Chapter 3: Understanding Windows Communication Foundation 39 WCF Programming Model 40 SO or OO 40 Service Model 41 WCF Programming Methods 49 WCF Programming Levels 51 The Development Process 52 And the Answer Is . 53 Installing WCF 53 Creating Your First WCF Service 56 Service Code 71 Service.svc 71 Web.config 71 Summary 72 Part II: Programming Windows Communication Foundation 73 Chapter 4: Addresses 75 WCF Addresses 75 Address Types 76 Address Formats 77 Programming WCF Addresses 80 EndpointAddress Class 80 Programming Addresses 83 Summary 86 Chapter 5: Understanding and Programming WCF Bindings 87 Understanding WCF Bindings 87 Predefined Bindings 88 Programming WCF Bindings 109 Using Code 110 Using Configuration Files 124 Summary 126 Chapter 6: Understanding and Programming WCF Contracts 127 WCF Contracts 128 Contracts and Their Relationship with the CLR 128 Service Contracts 128 viii 02_089842 ftoc.qxp 3/5/07 7:00 PM Page ix Contents Service Types 134 Data Contracts 140 Message Contracts 145 Programming WCF Contracts 151 Data Contract 151 Message Contract 158 Summary 163 Chapter 7: Clients 165 Client Architecture 165 Client Objects 166 Client Channels 168 Channel Factories 169 Client Communication Patterns 172 One-Way 172 Request-Reply 173 Duplex 174 Asynchronous 178 Creating Client Code 180 Generating Client Code 180 Defining Client Bindings and Endpoints 181 Typed versus Untyped Services 183 Invoking Operations of a Typed Services 183 Invoking Operations of an Untyped Service 184 Useful Information 184 Initializing Channels Interactively 184 Session and Channel Duration 185 Blocking Issues 185 Exception Handling 186 Client Programming Example 187 ChannelFactory 187 Duplex 193 Summary 199 Chapter 8: Services 201 Overview 201 Service Types 202 Service Contracts 205 Service Endpoints 206 ix 02_089842 ftoc.qxp 3/5/07 7:00 PM Page x ChapterContents # Service Behaviors 208 ServiceBehavior Attribute 209 OperationBehavior Attribute 216 Using Configuration to Specify Behaviors 218 InstanceContext 220 Handling Exceptions 220 FaultException 221 FaultContract Attribute 222 Programming Example 224 Summary 228 Chapter 9: Transactions and Reliable Sessions 231 Transactions 231 Overview 232 Transaction Attributes in System.ServiceModel 233 Reliable Sessions 237 Overview 237 Message Exchange 238 Securing Messages 240 Queues 243 Summary 251 Chapter 10: Security 253 Security Overview 254 Concepts 254 Why WCF Security? 256 Credentials 262 Security Behaviors and Bindings 263 Security Behaviors 263 Bindings 267 Securing Clients and Services 269 Best Practices 272 Summary 272 Chapter 11: Customizing Windows Communication Foundation 273 Extending ServiceHost and Service Model Layer 274 Client 274 Dispatcher 279 Behaviors 283 x 02_089842 ftoc.qxp 3/5/07 7:00 PM Page xi Contents Extending the Channel Layer 284 Client Channel 285 Service Channel 286 Channel Development 287 Extending Bindings 290 Building Custom Bindings 290 User-Defined Bindings 292 Summary 293 Chapter 12: Interoperability and Integration 295 Interoperability 296 Web Service Protocol Support 296 WSE (Web Service Enhancements) 298 ASP.NET Web Services 303 Integration 305 COM+ 305 MSMQ 308 Summary 310 Part III: Deploying Windows Communication Foundation 311 Chapter 13: Deploying Windows Communication Foundation 313 Installing WCF Services 313 Support
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages455 Page
-
File Size-