Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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 FREE CHAPTER 2. Hosting the HelloWorld WCF Service 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

Defining the HelloWorldService service contract interface

In the previous section, we created the solution and the project for the HelloWorld WCF service. From this section onwards, we will start building the HelloWorld WCF service. First, we need to define the service contract interface. For this, perform the following steps:

  1. In the Solution Explorer, right-click on the HelloWorldService project and select Add | New Item… from the context menu. The Add New Item dialog window shown in the following screenshot will appear on your screen:
    Defining the HelloWorldService service contract interface
  2. On the left-hand side of the window, select Installed | 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, which we are going to use as the service interface. Follow these steps 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 a WCF service contract interface:
    [ServiceContract]
  3. Add a GetMessage method to the interface. This method will take a string as the input and return another string as the result. It also has an attribute called OperationContract:
    [OperationContract]
    string GetMessage(string name);
  4. Change the interface to public.

The final content of the file, IHelloWorldService.cs, should look as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;

namespace HelloWorldService
{
    [ServiceContract]
    public interface IHelloWorldService
    {
        [OperationContract]
        string GetMessage(string name);
    }
}
You have been reading a chapter from
WCF Multi-layer Services Development with Entity Framework - Fourth Edition
Published in: Oct 2014
Publisher:
ISBN-13: 9781784391041
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 $19.99/month. Cancel anytime
Banner background image