Book Image

WCF 4.0 Multi-tier Services Development with LINQ to Entities

By : Mike Liu
Book Image

WCF 4.0 Multi-tier Services Development with LINQ to Entities

By: Mike Liu

Overview of this book

WCF is the Microsoft model for building services, whereas LINQ to Entities is the Microsoft ORM for accessing underlying data storage. Want to learn both? You would normally have to dig through huge reference tomes—so wouldn't you agree that a simple-to-follow practical tutorial on WCF and LINQ to Entities is the way to get ahead?This book is the quickest and easiest way to learn WCF and LINQ to Entities in Visual Studio 2010. WCF and LINQ to Entities are both powerful yet complex technologies from Microsoft—but you will be surprised at how easily this book will get you get up and running with them.Mastery of these two topics will quickly enable you to create Service-Oriented applications, and allow you to take your first steps into the world of Service Oriented Architecture without becoming overwhelmed.Through this book, you will learn what's going on behind the scenes with WCF, and dive into the basic yet most useful techniques for LINQ to Entities. You will develop three real-world multi-tiered WCF services from beginning to end, with LINQ to Entities being used in the data access layer of the services. Various clients including windows console applications, the WCF Test Client, Windows Form applications and WPF applications will be created to test these WCF services. By the end of this book, you will be 100% confident that you know WCF and LINQ to Entities, not only in theory, but with sound real-world experience.
Table of Contents (16 chapters)
WCF 4.0 Multi-tier Services Development with LINQ to Entities
Credits
About the Author
About the Reviewers
Preface
Index

Preface

WCF is the new Microsoft model for building services and LINQ to Entities is the new Microsoft ORM for accessing underlying data storages. Want to learn both? You may have already seen the huge reference tomes currently available.

This book is the quickest and easiest way to learn WCF and LINQ to Entities in Visual Studio 2010. WCF and LINQ to Entities are both powerful, yet complex technologies from Microsoft but this book will teach you both. The mastery of these two topics will quickly get you started in creating service-oriented applications and allow you to take your first steps into the world of Service-Oriented Architecture (SOA) without getting overwhelmed.

Throughout this book you will understand what's going on behind the scenes with WCF and learn the basic yet most useful techniques about LINQ to Entities. You will develop three real world, multi-tiered WCF services from beginning to end, with LINQ to Entities being used in the data access layer of the services. Various clients including Windows console applications, the WCF Test Client, Windows Form applications, and WPF applications will be created to test these WCF services. At the end of this book you will be 100 per cent confident that you understand WCF and LINQ to Entities, not only in theory, but also with sound real world experiences.

What this book covers

Chapter 1, Introducing Web Services and Windows Communication Foundation, covers the basic concepts of web services and WCF is also explained.

Chapter 2, Implementing a Basic HelloWorld WCF Service, discusses how a simple HelloWorld WCF service is implemented, hosted, and consumed.

Chapter 3, Hosting and Debugging the HelloWorld WCF Service, discusses various hosting and debugging techniques for WCF services.

Chapter 4, Implementing a WCF Service in the Real World, explains how to create a layered WCF service with an interface layer and a business logic layer.

Chapter 5, Adding Database Support and Exception Handling to the RealNorthwind WCF Service, explains how to add a data access layer and fault message handling to the previously created WCF service.

Chapter 6, LINQ—Language-Integrated Query, discusses LINQ-related language features such as anonymous types, extension methods, and lambda expressions.

Chapter 7, LINQ to Entities: Basic Concepts and Features, covers the basic concepts and features of LINQ to Entities such as LINQ to Entities designer, querying and updating a table, deferred execution, and lazy/eager loading.

Chapter 8, LINQ to Entities: Advanced Concepts and Features, discusses advanced concepts and features of LINQ to Entities such as stored procedures, inheritance, concurrency control, and transactional support.

Chapter 9, Applying LINQ to Entities to a WCF Service, covers how the data access layer of the WCF service will be recreated with LINQ to Entities.

Chapter 10, Distributed Transaction Support of WCF, explains how to add distributed transaction support to the WCF service.

What you need for this book

  1. Microsoft .NET Framework 4.0

  2. Microsoft Visual Studio 2010: Ultimate, Premium, or Professional

  3. Microsoft SQL Server 2008, 2005, or Express

  4. Internet Information Server 7.0 or 6.0

  5. Windows 7 or XP

Who this book is for

This book is for C# and C++ developers who are eager to get started with WCF and LINQ to Entities and want a book that is practical and rich with examples from the very beginning. Developers and architects evaluating SOA implementation technologies for their company will find this book particularly useful because it gets you started with Microsoft's tools for SOA and shows you how to customize our examples for your prototypes.

This book presumes basic knowledge of C# or C++. Previous experience with Visual Studio will be helpful but is not required as detailed instructions are given throughout the book.

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: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

public bool UpdateProduct(Product product)
{
// TODO: call business logic layer to update product
if (product.UnitPrice <= 0)
return false;
else
return true;
}

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

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name ="NorthwindConnectionString" connectionString="server=your_db_server\ your_db_instance; 
uid=your_user_name; pwd=your_password; 
database=Northwind" />
</connectionStrings>
<system.web>
<compilation debug="true" />
</system.web>

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

C:\SOAWithWCFandLINQ\Projects\HelloWorld\HelloWorldClient>
"C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\SvcUtil.exe" http://localhost:8080/HostDevServer/HelloWorldService.svc?wsdl /out:HelloWorldServiceRef.cs /config:app.config

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: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Note

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 on, 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 the book

Visit http://www.packtpub.com/files/code/1148_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

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 let us know 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.