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:
Add a reference of
System.ServiceModel.Web
to the service project,NorthwindService
.Open the
IProductService.cs
file in the project.Add a
using
statement:using System.ServiceModel.Web;
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 theUriTemplate
maps the parameter name,id
, from the HTTP protocol to the service operation...