Showing posts with label MVC Application Consuming WCF Service.. Show all posts
Showing posts with label MVC Application Consuming WCF Service.. Show all posts

Thursday, 4 January 2018

MVC Application Using WCF

Step 1 :
Ensure that the WCF project is open then start another instance of VS 2015. 
Then go to "File"-->"New"->"Project" then create an ASP .NET MVC Web Application . 
Name it "MVCWCFApp" then click "OK" button .
Then Select the project template "Internet Application" then click the "OK" button.




Step 2:
Create a Proxy using "Add Service Reference" by right clicking on Application in the Solution Explorer.
Note : Proxy is a class that converts a local request into a remote request.

A new window will open .paste the URL that you copied from the WCFMVCApp project into the address TextBox then click "GO".

In other words ,a proxy class is created successfully...
A ServiceRefernce will added into your project.


















Step 3:
Now add a new Controller then in solution Explorer select "Controller" then right click on it then select "Add Controller.
Name it UserController click the "Add" button.












Step 4:
Add the following code in the UserController.cs file.
Please build the project.

















Step 5:
Now right click inside the Index() method then select "Add View" then click on "Create a strongly Typed View" checkboc then select the model class we created,in other words "User(WebApplication.ServiceRefernce)" then select "Scaffold template List" then click the "Add" button.



















Step 6 :
Run the application
And see the results all the data in the user table is shown below the using WCF service.