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

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 January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services

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