This post explains you about building a REST-based service using Windows Communication Foundation(WCF) and ASP.NET 3.5. We develop this service without using the SOAP.You can read the REST Overview to get an understanding of what REST is? In simple tetchier statement we can say REST is WCF Web programming model.
1. Create a new web site in VS 2008 as follows
Select the HTTP from the location box and type the AdventureWeb in the name location box.
2. Add a new item by right clicking on the web site and select the LINQ to SQL Classes item from the dialogue box.
3.Drag the Employee table from the server explorer to the DBdesigner as follows
4.Add the EmployeeService.cs file to the App_Code folder and add the System.ServiceModel assembly to the web site. Write the following using statements in the EmployeeService Class.
5.Add the ServiceContract and AspNetCompatibilityRequirementsMode attributes to the above created class
6.Add the new class EmployeeResult.cs file to the web site then Add the DataContract attribute and two public fields to this class as follows.
7.Add the following code to the EmployeeService class
8.Add the new item to the web site by right clicking on solution explorer select the text file from the dialogue box then name it EmpService.svc.
9. Add the service host declaration with the following attributes
10. Now you have the REST service that returns XML and it can be consumed by any REST client. It would not be a browser.
11. See the svc file in browser which returns the employee names in xml format.
We have developed REST based WCF service in ASP.NET 3.5 without using the SOAP and can be consumed by any client. We can also use this service in ASP.NET Web sites.
|Share this post :|