How to use wcf service in MVC 5.

In this article, I m explain How to use wcf service in MVC 5.

In previous post I explained How to Create WCF Service in Visual Studio 2013.

Now Continue with previous post.

Create new project, Right Click on Solution Explorer and add new project.

Select ASP>NET Web Application with .NET Framework 4.5.


ASP.NET WEB APPLICATION

Select Empty MVC Template.


ASP.NET MVC WEB APPLICATION

Your MVC project add in solution explorer.

Now first copy wcf service url.(Please first check previous post here)


ADD SERVICE REFERENCE


Now EmployeeService service references add in your WebApplication.

SERVICE REFERENCE IN ECF

Now right click on Employee service and Click on Configure Service Reference. 

CONFIGURE SERVICE REFERENCE

Now uncheck Reuse type in referenced assemblies and click ok.

CONFIGURE SERVICE REFERENCE


Add New Controller in MVC application.
CONTROLLER IN MVC

Now add following code in Index action.


ADD VIEW IN MVC
Right click on Action method and Add View.

Now Select Template List and Model class.


ADD VIEW IN MVC

Your View code look like this.


VIEW IN MVC


Now Run Application(Ctrl + F5).


WCF APPLICATION

Enjoy..!

How to Create WCF Service in Visual Studio 2013

In this article, I am explain how to use WCF service.

First Open Visual Studio 2013. Create New Project and select WCF Service Application and give name WCFdemo.


WCF SERVICE

Then Click ok. Now In Solution Explorer Right Click on WCFdemo project and Add New Item ADO.net entity data model.


ado.net data model

Add Database here and select Table.


Entity data model

Now Your Solution explorer look like this.


wcf

Now Add New item WCF Service.

wcf service

Select WCF Service and give name.

wcf service

Now EmployeeServices.svc and IEmployeeServices.cs file add in solution explorer.

Create wcf service

Now Open EmployeeServices.svc.cs file and write following code.

wcf service

Here Employee is my database table and m9codersEntities is entity name.

Now Open IEmployeeServices.cs and write method name of EmployeeServices.svc.cs file.

interface in wcf

Now Build Project. (shortcut- F6)

Now Run EmployeeServices.svc file.(ctrl+F5)  

Then Open WCF Client popup window.

wcf test client

And your Service Adding...

wcf test client

After Service added successfully then copy url and paste into your browser.

wcf test service

You can see your all Method here and now use in any project.

In Next article i will explain how to use wcf service in MVC.