ebook img

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications: Over 85 easy recipes for managing communication between applications PDF

316 Pages·2010·19.277 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications: Over 85 easy recipes for managing communication between applications

www.it-ebooks.info Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications Over 85 easy recipes for managing communication between applications Steven Cheng professional expertise distilled P U B L I S H I N G BIRMINGHAM - MUMBAI www.it-ebooks.info Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: October 2010 Production Reference: 1141010 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849680-76-9 www.packtpub.com Cover Image by Vinayak Chittar ([email protected]) www.it-ebooks.info Credits Author Editorial Team Leader Steven Cheng Gagandeep Singh Reviewers Project Team Leader Frank Xu Lei Lata Basantani Kris van der Mast Dong Qi Project Coordinator Jovita Pinto Acquisition Editor Rashmi Phadnis Proofreader Sandra Hopper Development Editor Dhwani Devater Graphics Geetanjali Sawant Technical Editor Vinodhan Nair Production Coordinators Alwin Roy Adline Swetha Jesuthas Copy Editor Janki Mathuria Cover Work Alwin Roy Indexer Rekha Nair Monica Ajmera Mehta www.it-ebooks.info Foreword In the process of development and integration of enterprise applications and systems, SOA is a flexible set of design principles and is becoming more and more popular. Windows Communication Foundation (WCF) is a framework for building service-oriented applications, which are based on .NET. WCF 4 comes with a wide range of specific features as follows: • Simplified configuration • Standard endpoints • IIS hosting without an SVC file • WS-Discovery • Routing service (previously included with Dublin) • REST caching and Help page • Workflow services • Non-destructive queue receive • Simple byte stream encoding • ETW tracing Besides giving an introduction of the basic WCF concepts (such as endpoint, contract, binding, and address), this book also covers advanced topics such as security, extensions of Runtime, and diagnostics. By the way, this book also introduces the new features of WCF 4.0. Every section is excellent and is based on a real WCF application. It also provides a lot of sample code to help the readers understand how to implement it. It's really a good handbook for WCF learners. Thanks Steven for your hard work on this book. Frank Xu Lei MVP of Connected System Developer www.it-ebooks.info About the Author Steven Cheng is a senior support engineer at Microsoft Global Technical Support Center, where he has been supporting Microsoft software development technologies for more than five years. Currently, as a community leader, he is working actively in the MSDN newsgroup and forum communities. Steven Cheng's technical specialties cover many popular areas of Microsoft development technologies, including .NET framework, ASP.NET, XML Web Service, Windows Communication Foundation, SharePoint development, and so on. His blog can be found at http://blogs.msdn.com/stcheng. The publication of this book could not have been possible without the efforts put in by a large number of individuals. I would like to thank my colleague Andrew Zhu, who has helped me during the entire book authoring lifecycle. And thanks to my friends, Mian Li and Le Fei, who have given me lots of suggestions on the book recipes. Lastly, I offer my regards and blessings to all of those who supported me in any respect during the completion of this book. www.it-ebooks.info About the Reviewers Frank Xu Lei is the Microsoft MVP of Connected System Developer. He is also the moderator of Microsoft's Chinese WCF Forum. He has translated the book Inside Windows Communication Foundation into Chinese. He always focuses on Distributed Applications Development and EAI, based on .NET. Besides this, he is also a fan of NBA and sometimes, he goes to KTV with his friends. You can visit his blog at www.frankxulei.com. Dong Qi is an experienced .NET developer and has four years experience in .NET development. He worked at Microsoft as a development support engineer in the MSDN team. He now works at the Agree company as a .NET developer for Agree's frontend finance products. Agree is a leading financial consulting, software, and service provider company in China. He has written on .NET debugging and .NET security. Kris van der Mast, an active and dedicated moderator at the official ASP.NET forums, is a Microsoft MVP and ASP Insider. He's a well-known community member of several Belgian user groups. Kris is also a speaker for user groups in Belgium and abroad. You can find his blog at http://blog.krisvandermast.com. Kris currently works for Ordina Belgium, a consultancy company, as a senior .NET developer and architect. He also provides courses to clients in his specialization and technical interest—web technologies. www.it-ebooks.info Table of Contents Preface 1 Chapter 1: Working with Contracts 7 Introduction 7 Defining a one-way Contract 8 Make DataContract forward-compatible 11 Generate DataContract from an XML Schema 13 Using XMLSerializer to control message serialization 16 Using MessageContract to control the SOAP message 19 Adding a custom SoapHeader via Contract 20 Return custom exception data through FaultContract 23 Chapter 2: Endpoint, Binding, and Behavior 27 Introduction 27 Configuring Default Endpoints 28 Setting up two-way communication over MSMQ 31 Building a Publish-Subscribe service with dual binding 35 Creating a multiple-endpoint service 40 Implementing a POX HTTP service 43 Defining a CustomBinding without a timestamp header 47 Suppressing mustUnderstand validation on unknown SoapHeaders 49 Sharing a physical address between multiple endpoints 52 Chapter 3: Hosting and Configuration 55 Introduction 55 Hosting a service in a console application 56 Hosting a service in Windows Service 59 Hosting a HTTP service with ASP.NET-compatible context 63 Hosting a non-HTTP service in IIS 7 67 Customizing IIS ServiceHost via ServiceHostFactory 70 www.it-ebooks.info Table of Contents Specifying a dedicated service instance for a singleton service 72 Hosting a service in WSS 3.0 76 Chapter 4: Service Discovery and Proxy Generation 83 Introduction 83 Creating a typed service client 84 Choosing a specific type for representing a collection parameter 88 Reusing types between service and client 90 Customizing an auto-generated service proxy class in Visual Studio 94 Building an ad-hoc auto-discoverable service 96 Using managed ServiceDiscovery 99 Generating a service proxy in code 106 Customizing auto-generated service metadata 109 Chapter 5: Channel and Messaging 113 Introduction 113 Using ChannelFactory to consume a WCF service 114 Invoking async operation via ChannelFactory 116 Creating a service via ChannelListener 118 Getting the IP address of a client consumer of a WCF service 121 Adding a dynamic SoapHeader into a message 122 Chapter 6: Dealing with Data in Service 125 Introduction 125 Binding a WPF element with data from a WCF service 126 Returning ReadOnlyCollection data 128 Using raw XML as an operation parameter 130 Returning a DataTable/DataSet in a service operation 132 Transferring binary data with MTOM encoding 134 Specifying ServiceKnownType information in a programmatic way 136 Using XmlSerializer for custom data serialization 139 Chapter 7: Security 143 Introduction 143 Setting up ad hoc Windows authentication over plain HTTP 144 Getting an authenticated client identity in a service operation 146 Using username authentication with an ASP.NET membership provider 148 Sending a clear text username token over unsecured HTTP transport 150 Using transport and message security at the same time 153 Authorizing through declarative role-based access control 155 Impersonating with a client caller identity 158 Adding multiple tokens in a service request (supportingToken) 161 ii www.it-ebooks.info Table of Contents Supplying dedicated credentials for firewall or proxy authentication 165 Securing a dynamic SoapHeader 166 Chapter 8: Concurrency 171 Introduction 171 Hosting a singleton instance service 171 Invoking a WCF service without blocking the front UI 173 Using throttling to control service concurrency 176 Ensuring termination of a client session 178 Tuning WCF concurrency performance via Visual Studio testing tools 180 Chapter 9: Extending WCF Runtime 187 Introduction 187 Using a custom ServiceHost 189 Intercepting operation parameters in a strong-type manner 191 Filtering operation requests based on message 194 Generic operation error handling with OperationInvoker 198 Altering operation messages via MessageInspector 203 Building a custom MessageEncoder 208 Centralizing authorization through a custom ServiceAuthorizationManager 214 Chapter 10: RESTful and AJAX-enabled WCF Services 217 Introduction 217 Building a self-hosted REST service 218 Using an auto-generated Help page 221 Mapping URL suffix to operation parameters 223 Applying OutputCache in a REST service 226 Implementing file download via REST endpoint 228 Consuming a WCF service from an ASP.NET AJAX client 230 Accessing a remote REST service in an AJAX client 234 Chapter 11: Interoperability 237 Introduction 237 Building a WS-I Basic Profile 1.1 compatible service 238 Consuming an ASMX Web Service from a WCF client 240 Accessing a WCF service via the WebRequest component 243 Consuming a WCF service with a raw MSMQ program 246 Using a WCF Service in Microsoft Office 250 Chapter 12: Diagnostics 255 Introduction 255 Using the WCF Test Client tool to test a service 255 Capturing WCF request/response messages via Fiddler tool 258 iii www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.