Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Showing Data in MVC 4 using WCF service

Viewed:  2457 
Posted On:  11/01/2014 11:22:14 
How we can show data in MVC 4 applicaton uisng WCF and ADO.NET Entity framework ? 

In this article I am going to explain how we show data in a MVC application using WCF service.

Create a WCF Service Application.

MVC With WCF 1.png

Image 1.

Now right click on Solution Explorer -> Add New Item

MVC With WCF 2.png

Image 2.

MVC With WCF 3.png

Image 3.

Click New Connection -> Select Server Name -> Provide Authentication -> Select Data Base -> OK

MVC With WCF 4.png

Image 4.

MVC With WCF 5.png

Image 5.

MVC With WCF 6.png

Image 6.

MVC With WCF 7.png

Image 7.

Now Open Iservice1.cs file

Remove GetData() and GetDataUsingDataContract() method. Now Iservice1.cs should be like below, I added a new Interface GetEmployee().

MVC With WCF 8.png

Image 8.

Now Open Service1.svc.cs file

Remove GetData() and GetDataUsingDataContract() from here and implement GetEmployee() interface here.

MVC With WCF 9.png

Image 9.

Now Run the application.

MVC With WCF 10.png

Image 10.

 Now Create a MVC 4 application Name as MyMVCAppWithWCF

MVC With WCF 11.png

Image 11.

MVC With WCF 12.png

Image 12.

Now Right Click on Solution Explorer -> Add Service Reference.

MVC With WCF 13.png

Image 13.

MVC With WCF 14.png

Image 14.

Now Right Click on Controller -> Add Controller

MVC With WCF 15.png

Image 15.

Now  in Index do the following code:

MVC With WCF 16.png

Image 16.

MVC With WCF 17.png

Image 17.

Our VIEW is:

    ViewBag.Title = "Showing Data In MVC 4 using WCF Service";
    @Html.ActionLink("Create New""Create")
            @Html.DisplayNameFor(model => model.City)
            @Html.DisplayNameFor(model => model.Country)
            @Html.DisplayNameFor(model => model.Dept)
            @Html.DisplayNameFor(model => model.Emp_ID)
            @Html.DisplayNameFor(model => model.Mobile)
            @Html.DisplayNameFor(model => model.Name)
            @Html.DisplayNameFor(model => model.State)
    @foreach (var item in Model)
                @Html.DisplayFor(modelItem => item.City)
                @Html.DisplayFor(modelItem => item.Country)
                @Html.DisplayFor(modelItem => item.Dept)
                @Html.DisplayFor(modelItem => item.Emp_ID)
                @Html.DisplayFor(modelItem => item.Mobile)
                @Html.DisplayFor(modelItem => item.Name)
                @Html.DisplayFor(modelItem => item.State)
                @Html.ActionLink("Edit""Edit"new { id = item.ID }) |
            @Html.ActionLink("Details""Details"new { id = item.ID }) |
            @Html.ActionLink("Delete""Delete"new { id = item.ID })

Now Run the application. . .

MVC With WCF 18.png

Image 18.

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us