Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
WCF 4.0 Multi-tier Services Development with LINQ to Entities
WCF 4.0 Multi-tier Services Development with LINQ to Entities

WCF 4.0 Multi-tier Services Development with LINQ to Entities: Build SOA applications on the Microsoft platform with this hands-on guide updated for VS2010

eBook
R$80 R$245.99
Paperback
R$306.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

WCF 4.0 Multi-tier Services Development with LINQ to Entities

Chapter 2. Implementing a Basic HelloWorld WCF Service

In the previous chapter, we learned several WCF concepts and looked at a few code snippets.

In this chapter, we will implement a basic WCF service from scratch. We will build a HelloWorld WCF service by carrying out the following steps:

  • Create the solution and project

  • Create the WCF service contract interface

  • Implement the WCF service

  • Host the WCF service in the ASP.NET Development Server

  • Create a client application to consume this WCF service

Creating the HelloWorld solution and project


Before we can build the WCF service, we need to create a solution for our service project. We also need a directory in which we will save all the files. Throughout this book, we will save our project source codes in the C:\SOAWithWCFandLINQ\Projects directory. We will have a subfolder for each solution we create, and under this solution folder, we will have one subfolder for each project.

For this HelloWorld solution, the final directory structure is shown in the following image:

Note

You don't need to manually create these directories with Windows Explorer; Visual Studio will create them automatically when you create the solutions and projects.

Now follow these steps to create our first solution and the HelloWorld project:

  1. Start Visual Studio 2010. If the Open Project dialog box pops up, click on Cancel to close it.

  2. Go to menu File | New | Project. The New Project dialog window will appear.

  3. From the left-hand side of the window (Installed Templates...

Creating the HelloWorldService service contract interface


In the previous section, we created the solution and the project for the HelloWorld WCF service. From this section on, we will start building the HelloWorld WCF service. First, we need to create the service contract interface.

  1. In Solution Explorer, right-click on the HelloWorldService project, and select Add | New Item… from the context menu. The following Add New Item - HelloWorldService dialog window should appear on your screen.

  2. On the left-hand side of the window (Installed Templates), select Visual C# Items as the template, and from the middle section of the window, select Interface.

  3. At the bottom of the window, change Name from Interface1.cs to IHelloWorldService.cs.

  4. Click on the Add button.

Now an empty service interface file has been added to the project. Follow the steps below to customize it.

  1. Add a using statement:

    using System.ServiceModel;
  2. Add a ServiceContract attribute to the interface. This will designate the interface as...

Implementing the HelloWorldService service contract


Now that we have defined a service contract interface, we need to implement it. For this purpose we will reuse the empty class file that Visual Studio created for us earlier, and modify this to make it the implementation class of our service.

Before we modify this file, we need to rename it. In the Solution Explorer window, right-click on the file, Class1.cs, select rename from the context menu, and rename it HelloWorldService.cs .

Note

Visual Studio is smart enough to change all the related files which are references to use this new name. You can also select the file and change its name from the Properties window.

Next, follow the steps below to customize this class file.

  1. Change its namespace from HelloWorldService to MyWCFServices. This is because this file was added before we changed the default namespace of the project.

  2. Make it inherit from the interface, IHelloWorldService.

    	public class HelloWorldService: IHelloWorldService
  3. Add a GetMessage...

Hosting the WCF service in ASP.NET Development Server


HelloWorldService is a class library. It has to be hosted in an environment so that client applications may access it. In this section, we will explain how to host it using ASP.NET Development Server. Later, in the next chapter, we will discuss more hosting options for a WCF service.

Creating the host application

There are several built-in host applications for WCF services within Visual Studio 2010. However, in this section, we will manually create the host application so that you can have a better understanding of what a hosting application is really like under the hood. In subsequent chapters, we will explain and use the built-in hosting application.

To host the library using ASP.NET Development Server, we need to add a new website to the solution. Follow these steps to create this website:

  1. In Solution Explorer, right-click on the Solution file and select Add | New Web Site… from the context menu. The Add New Web Site dialog window...

Creating a client to consume the WCF service


Now that we have successfully created and hosted a WCF service, we need a client to consume the service. We will create a C# client application to consume HelloWorldService.

In this section, we will create a Windows console application to call the WCF service.

Creating the client application project

First, we need to create a console application project and add it to the solution. Follow these steps to create the console application:

  1. In Solution Explorer, right-click on the solution, HelloWorld, and select Add | New Project… from the context menu. The Add New Project dialog window should appear, as shown below.

  2. Select Visual C# | Console Application as the template, change the project name from the defaulted value of ConsoleApplication1 to HelloWorldClient, and leave the Location as C:\SOAWithWCFandLINQ\Projects\HelloWorld. Click on the OK button. The new client project has now been created and added to the solution.

Generating the proxy and configuration...

Summary


In this chapter, we have implemented a basic WCF service, hosted it within ASP.NET Development Server, and created a command line program to reference and consume this basic WCF service. At this point, you should have a thorough understanding as to what a WCF is under the hood. You will benefit from this when you develop WCF services using Visual Studio WCF templates or automation guidance packages. The key points covered in this chapter are:

  • A WCF service is a class library, which defines one or more WCF service interface contracts

  • The System.ServiceModel assembly is referenced by all of the WCF service projects

  • The implementations of a WCF service are just regular C# classes

  • A WCF service must be hosted in a hosting application

  • Visual Studio 2010 has a built-in hosting application for WCF services, which is called ASP.NET Development Server

  • A client application uses a proxy to communicate with WCF services

  • A configuration file can be used to specify settings for WCF services

Left arrow icon Right arrow icon

Key benefits

  • Master WCF and LINQ to Entities concepts by completing practical examples and applying them to your real-world assignments
  • The first and only book to combine WCF and LINQ to Entities in a multi-tier real-world WCF service
  • Ideal for beginners who want to build scalable, powerful, easy-to-maintain WCF services
  • Rich with example code, clear explanations, interesting examples, and practical advice – a truly hands-on book for C++ and C# developers

Description

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.

Who is this book 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.

What you will learn

  • Create, host, and consume your first WCF service in just a few minutes
  • Explore various hosting and debugging options for a WCF service
  • Build a multi-tier real-world WCF service from scratch to understand every layer of a WCF service and apply it to your real work
  • Add exception handling to your WCF services
  • Understand the basic and advanced concepts and features of LINQ and LINQ to Entities
  • Use LINQ to Entities in the data access layer of a WCF service
  • Control concurrent updates to databases with WCF and LINQ to Entities
  • Add distributed transaction support to your WCF services
  • Test a WCF service from a console program, the VS2010 built-in WCF Test Client, a Windows Form application, and a WPF test client

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 21, 2010
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781849681155
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Jun 21, 2010
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781849681155
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
R$500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts
R$800 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 920.97
WCF 4.0 Multi-tier Services Development with LINQ to Entities
R$306.99
Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
R$306.99
MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF
R$306.99
Total R$ 920.97 Stars icon

Table of Contents

10 Chapters
Introducing Web Services and Windows Communication Foundation Chevron down icon Chevron up icon
Implementing a Basic HelloWorld WCF Service Chevron down icon Chevron up icon
Hosting and Debugging the HelloWorld WCF Service Chevron down icon Chevron up icon
Implementing a WCF Service in the Real World Chevron down icon Chevron up icon
Adding Database Support and Exception Handling to the RealNorthwind WCF Service Chevron down icon Chevron up icon
LINQ—Language Integrated Query Chevron down icon Chevron up icon
LINQ to Entities: Basic Concepts and Features Chevron down icon Chevron up icon
LINQ to Entities: Advanced Concepts and Features Chevron down icon Chevron up icon
Applying LINQ to Entities to a WCF Service Chevron down icon Chevron up icon
Distributed Transaction Support of WCF Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(8 Ratings)
5 star 62.5%
4 star 12.5%
3 star 12.5%
2 star 12.5%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Danny Oct 04, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
good book
Amazon Verified review Amazon
Javaman Feb 09, 2011
Full star icon Full star icon Full star icon Full star icon Full star icon 5
After wasting $49.99 on Wrox's WCF 4, I purchased this book. Mike Liu and the editors at PACKT, did a great job of being Clear, Complete, and Concise. I wouldn't categorize this book to be for Experts, rather, for Beginners to Intermediates who just want to understand more on WCF 4.0 internals.Liu writes this book in a mathmatical fashion, first laying out the foundations and then building step by step. He even goes as far as to create a Service using no Visual Studio service templates for the purpose of exposing the fact that this is no magic, but rather a simple Interface and Attributed system that can be created from scratch.There are 9 chapters with 323 pages of information. The book is not one of those "Mule-Choking" monsters, as it is easy to handle. (I don't like Monster sized books). Chapters 6,7,8 and 9 expose the LINQ to SQL, LINQ to Entities and have really nicely laid out EF4.0 examples to allow you to model a Database Table (super easy using EF 4.0) and then expose the ORM Class via a WCF service. It's a completely new way to look at your MODEL or Business Layer support.One highly interesting thing about EF 4.0 is that of the Partial Method Support. Until now, I never really understood Partial Methods. Now I do, as you can regenerate and update your database schema and ORM mappings WITHOUT touching business logic that exists in the Partial Method implementations. This is so powerful that I am fully considering doing ALL my MODEL work in the MVVM design using EF4.0...A bit over priced in my opinion, but worth it to the professional looking to learn new stuff.
Amazon Verified review Amazon
Gray Nov 22, 2011
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was under pressure to learn WCF as my work project relied on it, and because I was searching the web for a good intro about the topic, I found a code snippet from CodeProject, followed the intructions and found that the article was a breeze to learn. That article was actually the chapter 2 of this book which I found out later in the comments, and immediately went to the bookstore and purchased it. It was a great decision as I have learned a lot from it from such a short time. I have compared this book with the step-by-step I have, and although both books are great, Mike Liu's book for me have taught what I need to learn the shortest time possible. The step-by-step is full of information but you have to read the very thick book just to understand the concept, which I don't have the luxury of time to do so.Both books will sit in my work desk, but for now, Mike's book and the layering technique would be the one I'm going to base all my services with.
Amazon Verified review Amazon
Duane Oct 14, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent book for WCF 4.0 and Entity Framework developers. I went through this book from front to the end and completed the exercises. By the time I reached the end of the book I had multiple versions of services that executed without errors.!The author did a great job at explaining the topics and the exercises were very well done.I recommend this book for people training in WCF development with the Entity Framework.!
Amazon Verified review Amazon
TallTale1004 Jan 13, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Doesn't over complicate the basics of designing a Multi-tiered WCF service.Mike Liu does a great job explaining the ideas in a manner anyone can understand.I look forward to reading more of his textbooks.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.