Book Image

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications

By : Juntao Cheng
Book Image

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications

By: Juntao Cheng

Overview of this book

The Windows Communication Foundation 4.0 (WCF 4.0) is a .NET-based application programming interface for building and running connected systems. It enables secure and reliable communication among systems within an organization or across the Internet. This book deals with the difficult issues faced by a .NET developer while working with WCF.WCF 4.0 is a communications infrastructure that unifies a broad array of distributed systems' capabilities in a composable, extensible architecture that supports multiple transports, messaging patterns, encodings, network topologies, and hosting models. This book is a collection of focused real-world recipes and covers basic recipes on topics such as working with contracts to more advanced topics such as extending WCF runtime. By the end of this book you will have valuable information that helps transform the potentially unproductive habits of .Net developers who work with WCF.This book will take you through many concepts starting with complete support for contract-related design for WCF service development. You will learn to use WCF's built-in feature for building various service endpoints. Service hosting and configuration are important areas for building WCF services, especially at the service deployment stage, and are detailed in this book. You will find it easy to work with WCF client proxy generation and metadata publishing and discovery when you go through recipes such as customizing auto-generated service proxies.The author then discusses the exchange of data in WCF service operation features, related to WCF data serialization. You will discover some useful tips for security in WCF service development and built-in features for developing concurrency control for your services built upon it.One big plus is that you will learn to extend the existing WCF framework to achieve advanced functionality. You will find a dedicated chapter for RESTful and AJAX-enabled service development. Moving on, you will find several useful WCF service interoperability cases, which are important for a distributed service development platform. Towards the end of this book you will find some handy and useful diagnostic methods for troubleshooting.
Table of Contents (20 chapters)
Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
Credits
Foreword
About the Author
About the Reviewers
Preface
Index

Preface

Windows Communication Foundation 4.0 (WCF 4.0) is a .NET-based application programming interface for building and running connected systems. It enables secure and reliable communication among systems within an organization or across the Internet. This book deals with the difficult issues faced by a .NET developer while working with WCF.

What this book covers

Chapter 1, Working with Contracts, shows how we can use Contract in WCF service development, including use cases of ServiceContract, DataContract, MessageContract, FaultContract, and so on.

Chapter 2, Endpoint, Binding, and Behavior, focuses on the basic building blocks of a WCF service, including endpoint, binding, and behavior. The recipes in this chapter demonstrate how to create various kinds of services by using the proper combination of these building blocks.

Chapter 3, Hosting and Configuration, covers several common and useful WCF service-hosting scenarios, such as hosting a WCF service in a Windows service, IIS web applications, and a WSS 3.0 site.

Chapter 4, Service Discovery and Proxy Generation, covers how to discover and consume WCF services. Recipes here demonstrate various scenarios of generating a WCF service proxy and introduces the service discovery feature in WCF 4.0.

Chapter 5, Channel and Messaging, digs into the channel layer of WCF programming and shows how to build WCF server and client applications through channel-layer components.

Chapter 6, Dealing with Data in Service, covers various data exchange and communication scenarios in WCF development. Recipes here include how to transfer XML and raw binary data or ADO.NET DataTable objects in service operations.

Chapter 7, Security, demonstrates how to utilize the built-in WCF security features such as service authentication, authorization, identity impersonation, message protection, and so on.

Chapter 8, Concurrency, introduces some typical cases about managing the concurrency and performance behaviors of a WCF service, such as how to use throttling settings and how to use Visual Studio testing tools for service performance tuning.

Chapter 9, Extending WCF Runtime, focuses on how to extend the existing components in the WCF programming model, such as customizing the default ServiceHost, using MessageInspector or MessageEncoder to intercept messages, customizing the service authorization logic, and so on.

Chapter 10, RESTful and AJAX-enabled WCF Services, provides several recipes on WCF REST service programming, including building a standard REST service, building an AJAX-enabled REST service, and consuming a remote REST service from an AJAX client.

Chapter 11, Interoperability, shows how to make a WCF service or client work with non-WCF or even non-.NET platform-based applications (such as a WebRequest client, legacy MSMQ client, or Microsoft Office client).

Chapter 12, Diagnostics, introduces some useful tools and skills for troubleshooting and diagnostics in WCF service development, including how to capture WCF messages, how to debug a Windows service host, how to use WCF performance counters, and so on.

Chapter 13, Miscellaneous WCF Development Tips, provides some additional skills and cases in WCF service development such as how to generate and manage test X.509 certificates and how to build an RSS feed and routing services.

What you need for this book

Though all the samples in this book are C# based, you don't have to be a very experienced C# developer. What is required is that you have a development machine with Visual Studio 2010 (Professional or Ultimate edition) and IIS installed, since the sample code is provided as Visual Studio 2010 solutions and some of them use IIS as host.

Who this book is for

If you work with Windows Communication Foundation 4.0 and want to be efficient when working with WCF features such as interoperability, proxy generation, and security, you will find this book very useful. With this book, you will be able to find quick and handy solutions for various kinds of service development scenarios using Microsoft Windows Communication Foundation 4.0. To follow the recipes, you will need to be comfortable with the .NET framework, C# programming, and the basics of SOA and how to develop them.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "There is also a corresponding WebInvokeAttribute for a HTTP POST request."

A block of code is set as follows:

[ServiceContract]
public interface IDataService
{
   [OperationContract]
   string GetData();
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[ServiceContract(Namespace="WCF.REST")]
public interface IDataService
{
   [OperationContract]
   [WebGet(ResponseFormat= WebMessageFormat.Json)]
   SimpleData GetData();
}

Any command-line input or output is written as follows:

certmgr -c -r localmachine -s my

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Selecting Add Service Reference will launch a dialog where one can control the configuration options on how the WCF service proxy gets generated".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Tip

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.