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
$22.99 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Estimated delivery fee Deliver to Ukraine

Economy delivery 10 - 13 business days

$6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

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 : 9781849681148
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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
Estimated delivery fee Deliver to Ukraine

Economy delivery 10 - 13 business days

$6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 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
$199.99 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 $5 each
Feature tick icon Exclusive print discounts
$279.99 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 $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 164.97
WCF 4.0 Multi-tier Services Development with LINQ to Entities
$54.99
Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
$54.99
MVVM Survival Guide for Enterprise Architectures in Silverlight and WPF
$54.99
Total $ 164.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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela