Book Image

WCF Multi-layer Services Development with Entity Framework - Fourth Edition

By : Mike Liu
Book Image

WCF Multi-layer Services Development with Entity Framework - Fourth Edition

By: Mike Liu

Overview of this book

Table of Contents (20 chapters)
WCF Multi-layer Services Development with Entity Framework Fourth Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Hosting the HelloWorld WCF Service
Index

Creating the RESTful service


Now we have the solution ready and have hosted the service in IIS. Next, we will modify the existing NorthwindService to be RESTful. We will modify the service contracts, service implementation, and web config file.

Defining RESTful service contracts

In the existing NorthwindService, we have defined two operations for the service, GetProduct and UpdateProduct. To make them RESTful, we need to change their definitions using the following steps:

  1. Add a reference of System.ServiceModel.Web to the service project, NorthwindService.

  2. Open the IProductService.cs file in the project.

  3. Add a using statement:

    using System.ServiceModel.Web;
  4. Add the following line of code before the GetProduct method:

    [WebGet (UriTemplate = "Product/{id}" , ResponseFormat = WebMessageFormat.Json )]

    In the preceding line of code, we tell the WCF runtime engine that this operation will be a HTTP Get operation and the UriTemplate maps the parameter name, id, from the HTTP protocol to the service operation...