REST stands for the Representational State Transfer, which is an architectural style for networked hypermedia applications. It is primarily used to create the Service, which is lightweight, maintainable and scalable. A Service based on REST is called RESTful Service.
This article explains how to create RESTful Service, using WCF (Windows Communication Foundation).This can be accomplished in the steps given below.
Create WCF Project
- Open Visual Studio.
- Add New ASP.NET Web Application.

- Choose Empty and select Web Form, if you are using Visual Studio 2015.

Now, we are ready with our project and let's add the Service named “Cricket”.
Adding Datacontract
Thus, we are ready with our Service, which will do our work for us. Now, the next step is to add the Datacontract, which will be used to pass the data to and from the Services .
- [DataContract]
- publicclassCricketer {
- [DataMember]
- publicstring Name {
- get;
- set;
- }
- [DataMember]
- publicstring Team {
- get;
- set;
- }
- [DataMember]
- publicstring ODI {
- get;
- set;
- }
- [DataMember]
- publicstring Test {
- get;
- set;
- }
- }
Thus, we are ready with the DataContractClass. Lets see what changes are required to make to the ServiceContract.
ServiceContract
The main part of the RESTful Service is the Service contract part that is our interface, which has defined Operation contract. Our Service contract is given below.
- using System;
- usingSystem.Collections.Generic;
- usingSystem.Linq;
- usingSystem.Runtime.Serialization;
- usingSystem.ServiceModel;
- usingSystem.Text;
- usingSystem.ServiceModel.Web;
- usingWCFRestServices;
- namespaceWCFRestServices {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICricket" in both code and config file together.
- [ServiceContract]
- publicinterfaceICricket {
- [OperationContract]
- [WebInvoke(UriTemplate = "/GetCricketer", Method = "Get", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
- CricketerGetCricketerDetails();
- [OperationContract]
- [WebInvoke(UriTemplate = "/AddCricketer", Method = "Post", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
- intAddCricketer(CricketerobjCricketer);
- }
- }


Former memberPosted Dec 12, 2016, 3:41 AM
How to call this function CricketerGetCricketerDetails() from client side ? what will be the url ? do we need to create proxy to make call from client side ? or can we call wcf function like web api using rest like url ?
Ranjan MallickPosted Dec 7, 2016, 5:51 AM
Hi Mangesh Nice Article but need some explanation regarding how user can cosume this service on different platform like Web,Mobile ...If that part you can elaborate it will be great...