Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WCF Multi-layer Services Development with Entity Framework - Fourth Edition

You're reading from   WCF Multi-layer Services Development with Entity Framework - Fourth Edition Create and deploy complete solutions with WCF and Entity Framework

Arrow left icon
Product type Paperback
Published in Oct 2014
Publisher
ISBN-13 9781784391041
Length 378 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Mike Liu Mike Liu
Author Profile Icon Mike Liu
Mike Liu
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Implementing a Basic HelloWorld WCF Service 2. Hosting the HelloWorld WCF Service FREE CHAPTER 3. Deploying the HelloWorld WCF Service 4. Debugging the HelloWorld WCF Service 5. Implementing a Three-layer WCF Service 6. Adding Database Support and Exception Handling 7. LINQ to Entities – Basic Concepts and Features 8. LINQ to Entities – Advanced Concepts and Features 9. Applying LINQ to Entities to a WCF Service 10. Distributed Transaction Support of WCF 11. Building a RESTful WCF Service 12. WCF Security 13. Extending WCF Services Index

Implementing the HelloWorldService service contract

Now that we have defined a service contract interface, we need to implement it. For this purpose, we will re-use the empty class file that Visual Studio created for us earlier and modify it 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 Class1.cs file, select Rename from the context menu, and rename it as HelloWorldService.cs. Visual Studio is smart enough to change all the related files that are references to use this new name. You can also select the file and change its name from the Properties window.

Next, perform the following steps to customize the class file:

  1. Open the HelloWorldService.cs file.
  2. Make it implement IHelloWorldService implicitly as follows:
    public class HelloWorldService: IHelloWorldService
  3. Add a GetMessage method to the class. This is an ordinary C# method that returns a string. You can also right-click on the interface link and select Implement Interface to add the skeleton of this method.
    public string GetMessage(string name)
    {
      return "Hello world from " + name + "!";
    }

The final content of the HelloWorldService.cs file should look like the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorldService
{
    public class HelloWorldService: IHelloWorldService
    {
        public string GetMessage(string name)
        {
            return "Hello world from " + name + "!";
        }
    }
}

Now, build the project. If there is no build error, it means that you have successfully created your first WCF service. If you see a compilation error such as 'ServiceModel' does not exist in the namespace 'System', this is because you didn't add the System.ServiceModel namespace reference correctly. Revisit the previous section to add this reference and you are all set.

Next, we will host this WCF service in an environment and create a client application to consume it.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime