Create A WCF Service
First of all, On Visual Studio Click on File --> New --> Project.
A new window will open as shown below.
Select WCF --> WCF Service Application --> OK.
This much of steps will create a WCF Service Application.
In the Solution, there will be mainly having following files.
1. Service file (Service1.svc)
2. Interface file (IService.cs).
Inside Interface file, there is having one Method corresponding to each Method on the SVC file.
On the Interface file, we can get the definition of methods only.
In the Interface file, the Interface comes under [ServiceContract].
Each Interface method comes under [OperationContract] as shown below.
On the Service file (SVC file), we have to write down the logic of the method.
Performing database operation or implementing business logic will be done on the SVC file.
In the above example, GetData would return a string value.
The defintion of methods on SVC file will be same as in Interface file.
Defintion means Input, Output and Method Name under [OperationContract] on the Interface file.
Compile And Run A WCF Service
Set WCF project as Set As Start Project.
For Running the WCF Service, just set the SVC file as Set As Start Page.
Then click DEBUG --> Start Debugging.
This will open WCF Test Client.
There just double click on the GetData method to test the Service.
Here we have given the Input as 1 and the output obtained is "You entered 1".
By this way we can create and test WCF Service in Visual Studio.