According to Wiki, Restful Webs services are described as:
A RESTful web service (also called a RESTful web API) is a simple web service implemented using HTTP and the principles of REST. It is a collection of resources, with three defined aspects:
•the base URI for the web service, such as http://example.com/resources/
•the Internet media type of the data supported by the web service. This is often JSON, XML or YAML but can be any other valid Internet media type.
•the set of operations supported by the web service using HTTP methods (e.g., POST, GET, PUT or DELETE).
For programming Restful services in .Net Framework, till visual studio 2008 sp1, there was a separate kit for named “WCF REST Starter Kit Preview 2” at:
But it was not upgraded for Visual studio 2010. So for Visual studio 2010/.Net 4.0, search WCF+REST related items in Visual studio gallery.
One of the best template by WCF Team in Microsoft is as below:
Download file named “WcfRestService40(CS).vsix”, and double click to install the template.
Now a new project type named “WCF REST Service application” is added.
I created a new project based on new project type named “WcfRestServiceApp”.
Added a console project to solution for running service named “ServiceServerApp”, with following code
WcfRestServiceApp.Service1 serv = new WcfRestServiceApp.Service1();
WebServiceHost host = new WebServiceHost(serv, new Uri("http://localhost/WCFRESTService/"));
Console.WriteLine("Service is running....Press enter to stop the service...");
When you try to run service, you will get following error:
In order to use one of the ServiceHost constructors that takes a service instance, the InstanceContextMode of the service must be set to InstanceContextMode.Single. This can be configured via the ServiceBehaviorAttribute. Otherwise, please consider using the ServiceHost constructors that take a Type argument.
As error explains, I have to change InstanceContextMode from InstanceContextMode.PerCall
After that I got following error:
HTTP could not register URL http://+:80/WCFRESTService/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).
So solution is to run following command incase of windows 7.
netsh http add urlacl url=http://+:80/WCFRESTService/ user=juliet\shah
For theory details see the link above.
So I am ready with service running .
While analyzing code of template, two things are important to note.
•Template uses the WebGetAttribute and WebInvokeAttribute to associate service operations with both GET and other HTTP verbs like PUT, POST, and DELETE.
•Template uses the UriTemplate and UriTemplateTable classes to provide URI processing capabilities.
For details about theory visit following
That all from my side for RestFull web Services in .Net framework 4.0/Visual studio 2010