SharePoint Pals
 | Sign In
Hosting a WCF Service Using Windows Service Hosting
by Shikha Gupta 5 Jul 2016
SharePoint Developer
Today  :   7     Total  :    1481

We have created the WCF and have done self-hosting and Windows Service hosting and we can host the same WCF through IIS. Hosting through IIS is the most common way to do so. In order to do so follow the following steps and if you want to see how to create the WCF and the client application then click here.

1. Right click on EmployeeClassLibraryService Solution and click on add a website and then select WCF then click on browse to open the solution where you have created the EmployeeClassLibraryService Solution.

2. Once you have that click on open and for this website you can just add EmployeeServiceIISHost to its name.

3. Once you have the EmployeeServiceIIS host in the solution then expand the App_code and delete the IService.cs and Servcie.cs as this is for WCF service but we already have our WCF ready.

4. Right click on the website and click on add reference of EmployeeClassLibraryService project.

5. Rename Service.svc file to EmployeeService.svc and delete the existing code and copy paste the following code. The service attribute basically holds namespace.service name. We have remove the code behind tag because we don’t have the service in app_code folder we have deleted the services which we had in this folder.

<%@ ServiceHost Language="C#" Debug="true" Service="EmployeeClassLibraryService.EmployeeService" %>

6. Open the Web.config file and delete the configuration and copy and paste the following configuration. It is the same piece of code which we had in app.config file for self-hosting or web-service hosting.

 <?xml version="1.0" encoding="utf-8" ?>
     <add name ="EmpCS" connectionString="Data Source=PC258762\MSSQLSERVER2008;Initial Catalog=DbEmployee;Integrated Security=True" providerName="System.Data.SqlClient" />
       <service name="EmployeeClassLibraryService.EmployeeService" behaviorConfiguration="mexBehavior">
         <endpoint address="EmployeeService" binding="basicHttpBinding" contract="EmployeeClassLibraryService.IEmployeeService"></endpoint>
             <add baseAddress="http://localhost:8090"/>
         <behavior name="mexBehavior">
           <serviceMetadata httpGetEnabled="true"/>

7. Build the solution.

8. Now we need to create a virtual directory in IIS. In the run window type intemgr this will open the IIS.

9. Expand Sites and in the default website right click on it and click on add application.

The details Entered is shown below:



Application Pool

.Net v4.5

Physical Path

C:\Users\430379\Documents\Visual Studio 2013\Projects\EmployeeClassLibraryService\EmployeeServiceIISHost

10. Once the application is added then right click on it and click on option switch to content view and then on the EmployeeService.svc right click on it and click on Browse.

11. Once you click on the browse button then it should open the following link


12. You can also find the link of your wsdl document which might be a bit different in your case something like :

13. Open the Employee Client application which we have created in the previous article. For more information on how to create client application which will consume this WCF click here.

Now in Employee Client Application delete the service reference which was previously added and delete the service reference folder as well.

14. Now add a new Service reference and copy and paste the wsdl document link and click go this will discover your service give a proper namespace like EmployeeService and click ok.

15. Now Run the client application and test both the functionality

Save Employee:

Get Employee:

We have hosted the WCF in IIS without writing a single line of code for hosting as we had to do in Self hosting or Web Service Hosting. We had our service in the same application but we can even have it in different applications or in App_code folder.

Happy Coding J

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