Articles → WCF → Hosting WCF On IIS

Hosting WCF On IIS






Software Requirement





Prerequisite Knowledge




  1. What is WCF service?
  2. What is a service contract?
  3. What is an operation contract?
  4. Basics about IIS.
  5. How to create projects using visual studio?

Steps Of Execution




  1. Create a new WCF service
  2. Host it on IIS
  3. Check if service is hosted correctly on IIS
  4. Create a new client application



Benefit Of Hosting A Service On IIS Over Console Application





Create A New WCF Service




Picture showing selecting the WCF service application project type from visual studio installed template
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




Picture showing the popup window for selecting the publish method
Click to Enlarge



Picture showing the popup window for selecting the target location
Click to Enlarge



Picture showing selecting the IIS as the target location
Click to Enlarge



Picture showing a button for creating the new web application on IIS
Click to Enlarge



Picture showing creating an application WCFService in IIS
Click to Enlarge



Picture showing selecting the target location of the application
Click to Enlarge




Check If Service Is Hosted Correctly On IIS




  1. Open run and write Inetmgr.
  2. Click Ok. An IIS manager will be opened.
  3. On the left hand side section expand Default Web Site and right click on the service application as shown in figure below
  4. Picture showing the context menu with switch to content view option
    Click to Enlarge

  5. Click on Switch to Content View.
  6. You can see the service files on the right hand side. Right click on the file Service1.svc and click on Browse.
  7. Picture showing the Browse option in context menu
    Click to Enlarge

  8. On click of browse a browser will open in a new window as shown in figure below
Picture showing the WCF service on the browser
Click to Enlarge




Create A New Client Application




Picture showing adding the new client application in the solution
Click to Enlarge



Picture showing adding the reference of WCF service in the client application
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




Picture showing the output of the WCF service hosted on IIS
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, July 25, 2013

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250