SharePoint Pals
 | Sign In
Steps to perform WCF IIS hosting
by Tarun Kumar Chatterjee 31 May 2016
.Net – Technology Specialist
Today  :   11     Total  :    2507

The main advantage of IIS hosting service is that, it will automatically launch the host process when it gets the first client request. It uses the features of IIS such as process recycling, idle shutdown, process health monitoring and message based activation. The main disadvantage of using IIS is that, it will support only HTTP protocol.

Start the Visual Studio and click File -- >New -- >Web Site. Select the 'WCF Service Application' click OK.


I have created a service named as MyService, which will accept value as input and return as “You entered: value”. Interface and implementation of the Service is shown below.

Add a WCF service with the following codes


Below is the IISHostedWCFService interface code:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.Serialization;
 using System.ServiceModel;
 using System.Text;
 namespace IISHostedWCFService
     public interface IMyService
         string GetData(int value);
         CompositeType GetDataUsingDataContract(CompositeType composite);
     public class CompositeType
         bool boolValue = true;
         string stringValue = "Hello ";
         public bool BoolValue
             get { return boolValue; }
             set { boolValue = value; }
         public string StringValue
             get { return stringValue; }
             set { stringValue = value; }
 Below is the interface implement code: 
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.Serialization;
 using System.ServiceModel;
 using System.Text;
 namespace IISHostedWCFService
     public class MyService : IMyService
         public string GetData(int value)
             return string.Format("You entered: {0}", value);
         public CompositeType GetDataUsingDataContract(CompositeType composite)
             if (composite == null)
                 throw new ArgumentNullException("composite");
             if (composite.BoolValue)
                 composite.StringValue += "Suffix";
             return composite;

Right click on IISHostedWCFService and go to Properties. Go to Web, Select “Use Local IIS Web Server”, set the project URL properly and then click on Create Virtual Directory. It will be successfully created the virtual directory in IIS.


Here is my web.config code

 <?xml version="1.0"?>
     <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
     <compilation debug="true" targetFramework="4.5.1" />
     <httpRuntime targetFramework="4.5.1"/>
       <service name="IISHostedWCFService.MyService">
 	    <endpoint address="http://localhost/IISHostedWCFService/MyService.svc" binding="wsHttpBinding" contract="IISHostedWCFService.IMyService">
 	    <dns value="localhost"/>
 	    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
           <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />          
           <serviceDebug includeExceptionDetailInFaults="false"/>
     <modules runAllManagedModulesForAllRequests="true"/>    
     <directoryBrowse enabled="true"/>

Now my service is ready, build it and browse


If we open the WSDL link it will show you the WSDL xml content properly.

To host the service, let’s add another client console application within the solution named as “IISHostedWCFClient”

Within the console application add service reference named as “MyServiceReference” and using the Address http://localhost/IISHostedWCFService/MyService.svc


Within the Program.cs add the following code:

 static void Main(string[] args)
              MyServiceReference.MyServiceClient client = new MyServiceReference.MyServiceClient();
              Console.WriteLine("Client calling the service...");             

Now run the console application, it will pass the value 5 to service and display the result as:


Happy Coding

Tarun Kumar Chatterjee

Tags :  , , ,

blog comments powered by Disqus

SharePoint Pals

SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile


Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community

SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to in a word document.

Related Resources

Recent Tweets

Twitter October 23, 22:21
How to Add/Remove User Custom Actions (in Site Actions Menu) Programmatically using CSOM PNP in SharePoint -

Twitter October 21, 21:34
How to Add a JS Link Reference to the Display Form or Any other ASPX Programmatically using CSOM PNP in SharePoint -

Twitter October 20, 13:01
How to Add a JS Link Reference to the NewForm and EditForm Programmatically using CSOM PNP in SharePoint Office 365-

Twitter October 12, 12:15
How to Deploy Provider Hosted Apps (Add-Ins) by App Stapling in SharePoint Office 365 -

Twitter October 11, 13:39
How to Deploy Provider HostedApp programmatically using CSOM in SharePoint Office 365 Activating Developer Feature -

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation