Hosting WCF Service Under a Local IIS

In this article, we will see how to host a WCF service under IIS (Internet Information Services).

Introduction
 
In this article, we will see how to host a WCF service under IIS (Internet Information Services). In my last article, we saw how to host our WCF service under a windows service. As all of you know we can host the WCF service in various ways; in this article, we will see one of them i.e. IIS hosting.

If we host our service under IIS then we have all the features of IIS like process recycling, ideal shutdown etc. Visual Studio provides two different ways to host our WCF service in a local IIS in all are familiar with Publishing Wizard. Here we will discuss the second way using Visual Studio only in a simple manner to host our WCF service in local IIS. To host the WCF service follow the steps below.
 
Step 1: Open your Visual Studio in Administrator mode by right clicking on it and create one new WCF service application which will create a default Service1.svc and Service.cs and IService.cs classes.
 
Step 2: Now open Solution Explorer and right-click on the solution and select properties which will open the property window.
 
Step 3: In the opened project properties window, select the WEB tab and on the right side under servers select Local IIS Web Server. Provide the service URL and click on the create virtual directory button in front of it like below.
 
mg1.gif
 
Step 4: After doing this it will show the message that our service has been hosted successfully; to confirm it open the IIS manager (MMC console) and see here under default web sites our service is available like below.
 
mg2.gif
 
Step 5 : Now we can browse our service through a browser; to do this open any browser and type the full URL to our service like below:
 
mg3.gif
 
That's done; we have hosted our WCF service under our local IIS using a very easy way.
 
Conclusion
 
In this simple way, we can host our WCF service under IIS using Visual Studio.