.netWCF

Hosting a WCF service in Windows service(Part – 19)

This is in continuation to part 17.
Self Hosting WCF service
Let’s create a Windows service and add it to WCFSelfHostService solution.

  • Right click on solution–>add–>New Project–>Rename it to WindowsServiceHost.
  • Add reference to WCFSelfHostService
  • Add reference to System.ServiceModel
  • Add new configuration file to WindowsServiceHost–>Right click on WindowsServiceHost–>Add app configuration file
  • We will copy the configuration from Host to WindowsServiceHost app.config
  • Rename service1.cs to WCFWindowsService.cs
  • Then go to design–>Right click–>Add Installer
  • serviceInstaller1–>Right click–>go to properties–>specify the service name as WCFWindowsService and make the start type to Automatic
  • Right click on serviceProcessInstaller1 from designer and go to properties and select Account as local system
  • Build the solution
  • Start–>All programs–>visual studio–>visual studio tool–>visual studio command prompt
  • install – i
  • You can get the exe path from right click on WindowsServiceHost–>Open window in file explorer–>bin–>debug and windowsHostService.exe
  • hit enter and the install would be completed
  • then go to Run–>services.msc and in services windows you will see the installed WindowsHostService and you can start it manually
  • To uninstall you can use option -u
  • Now you can open the WCFSelfHostCLient and update service reference and run the client to test if the service is hosted correctly or not

© 2015, www.techkatak.com. All rights reserved.