Here in this tutorial, you are going to follow a simple step by step approach to create a WCF Data Service. You need Visual Studio 2010 IDE & SQL Server in your machine as prerequisites for building WCF Data Service. It would be nice if you have the basic .NET knowledge. Let's get started!

Step 1

Open Visual studio 2010 and create a Web -> ASP.NET Web Application with a language of your choice, either C# or VB. I’ve used C# throughout the lesson. The reason why we are creating an ASP.NET Web application is because in order to host and consume the WCF Data Service we need a hosting and client application.

Step 2

Once the application is created, you need a DataModel where it is going to be served. So let’s create a SQL Server database. Right click on the App_Data -> Create SQL Server database and define the schema as below and let’s feed some values into our newly created database table.

Step 3

You have your Database and Table ready, now it’s time for you to create an Entity Data Model. Right click on the project and Add New item -> Select ADO.NET Entity Data Model, a Wizard pops up, proceed further with it. Below screenshots helps you building a Model.

Step 4

Now, you are done with Entity Model and for our Schema structure, this how the Model looks:

Step 5

You are good with our basic implementation in-order to adopt a WCF Data Service into our application. Ready to go. Let’s create a WCF Data Service. Right click on the Project -> Add New Item -> Select WCF Data Service.

Step 6

WCF creates us a basic template code for us to start with.

Step 7

Before moving forward, let us keep our Database Entity name handy. It can be found in Web.Config under Connection String.

Step 8

Here you have replaced the template code with EntityName and Set of rules which decides the rights of access.

Step 9

If you run the application or just hit F5 selecting the WCF Data Service file. It opens up a browser and navigates us to http://localhost:/WCFDataFilename.svc . You can see a XML document with title holds to the Entity Name we created.

Step 10

To get the full database values as a XML model, just postfix the Entity Name with URL. As below:

Step 11

Quite simple right! You do have some syntax approach in accessing the resource via OData. For example, if you need a Single record, access it like below:

 

 

HostForLIFE.eu WCF with Free ASP.NET Hosting
Try our WCF with Free ASP.NET Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service for the next 3 days. Once your trial period is complete, you decide whether you'd like to continue.