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

Monday, 1 January 2018

MVC Application Using WCF Service

Creating ASP  .NET  MVC App With  WCF Service.

Step 1 :


Go to VS 2015 and Select "File"--> "New Web Site" then select "WCF Service" then provide the specific root path and provide the name "WCFMVCApp".

















Click on "OK" then create a solution.




















Step 2 :

Go to the solution Explorer then go to "WCFMVCApp" then right click on it then select "Add"->"Add new item"-> "Add ADO .Net Entity data model". Then click the "Add" button then place the file in the App_code folder.



















Step 3 :

Then the Entity Data Model Wizard will be shown. Select "Generate data from database " then click the "Next" button.



















Step 4:

Choose your data connection. I am selecting my existing database of SQLServer 2016.
Activate the radio button "Yes include the sensitive data in the connection string".
Save the connection string in the config file by enabling the check box "Save entity connection setting in web.config as then click the Next button.




















Step 5 :
Choose which database object you want in your model.here i am selecting the one of the table

Create table Users
UserID int constraint pk primary key,
FirstName varchar(30) not null,
LastName varchar(30),
Email varchar(30));

you can use the above table or create your own table and use it.
Then click the "Finish" button.
Please ensure that in the Solution Explorer under the App_code folder the Model.edmx file has been created.
Your entity data model is ready for use.

























Step 6 :

Go to Solution Explorer then expand the App_code folder then go to the Iservice.cs file.




















Step 7:

Delete the Getdata() and GetDataUsingDataContract() methods.
Then i am writing one method GetUser() as follows.


















Step 8:

Then go to the Service.cs file and implement the method declared in the IService.cs interface.
In the Service.cs file right click the Iservice Interface then select "Implement Interface"-->"Implement Interface".

Delete the already present method in the Service.cs the file. And write the following code in the "public List<ASPUser>GetUser()" method.
Is showing below code.


























Step 9:

Open the Service.svc file and now run the project.
A new window will open,copy the URL present in that window and paste it into any text file. This URL will be used in the next project.





















http://localhost:55708/Service.svc