Articles → WCF → Hosting WCF On IIS
Hosting WCF On IIS
Software Requirement
Prerequisite Knowledge
- What is WCF service?
- What is a service contract?
- What is an operation contract?
- Basics about IIS.
- How to create projects using visual studio?
Steps Of Execution
- Create a new WCF service
- Host it on IIS
- Check if service is hosted correctly on IIS
- Create a new client application
Benefit Of Hosting A Service On IIS Over Console Application
Create A New WCF Service
Click to Enlarge
using System.ServiceModel;
namespace WCFService {
[ServiceContract]
public interface IService1 {
[OperationContract]
string GetData(int value);
}
}
namespace WCFService {
public class Service1: IService1 {
public string GetData(int value) {
return string.Format("You entered: {0}", value);
}
}
}
Host It On IIS
Click to Enlarge
Click to Enlarge
Click to Enlarge
Click to Enlarge
Click to Enlarge
Click to Enlarge
Check If Service Is Hosted Correctly On IIS
- Open run and write Inetmgr.
- Click Ok. An IIS manager will be opened.
- On the left hand side section expand Default Web Site and right click on the service application as shown in figure below
Click to Enlarge
- Click on Switch to Content View.
- You can see the service files on the right hand side. Right click on the file Service1.svc and click on Browse.
Click to Enlarge
- On click of browse a browser will open in a new window as shown in figure below
Click to Enlarge
Create A New Client Application
Click to Enlarge
Click to Enlarge
using System;
namespace WCFClient {
class Program {
static void Main(string[] args) {
ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
Console.WriteLine(proxy.GetData(1));
Console.ReadKey();
}
}
}
Output
Click to Enlarge