The operation of Windows service hosting is a simple one. Given beneath are the steps with requisite coding and screenshots that explain the process in an easy way.
Step-1: Now let’s create a WCF service. Open Visual Studio 2008 and click New → Project and select Class Library from the template.
Step-2: Add reference System.ServiceModel to the project. This is the core assembly used for creating the WCF service.
Step-3: Next, we can create the ISimpleCalulator interface. Add the Service and Operation Contract attribute as shown beneath:
Step-4: Implement the ISimpleCalculator interface as shown beneath:
Step-5: Build the Project and get the dll. Now, we are ready with the WCF service. We are going to see how to host the WCF service in Windows service.
Note: In this project, it is mentioned that we are creating both Contract and Service (implementation) in the same project. However it is always a good practice if you have both in different projects.
Step-6: Open Visual Studio 2008 and Click New → Project and select Windows Service.
Step-7: Add 'WindowsServiceHostedService.dll' as reference to the project. This assembly is going to act as service.
Step-8: The OnStart method of the service can be used to write the hosting code for WCF. We have to make sure that we are using only one service host object. OnStop method is used to close the Service Host. The subsequent code shows how to host the WCF service in Windows service.
Step-9: In order to install the service, we need to have the Installer class for the Windows service. So add a new Installer class to the project, which is inherited from the Installer class. Given beneath is the code that shows the Service name, StartUp type, etc. of the service.
Step-10: Build the project to get the executable file WCFHostedWindowsService.exe. Next, we need to install the service using the Visual Studio Command Prompt. So open the command prompt by clicking Start→All Programs→Microsoft Visual Studio 2008→Visual Studio Tools→ Visual Studio Command Prompt. Using the install util utility application, you can install the service as shown beneath.
Windows Communication Foundation (WCF) Related Interview Questions
|VB.NET Interview Questions||C#. NET Interview Questions|
|Adv Java Interview Questions||SQL Server 2008 Interview Questions|
|ASP.NET Interview Questions||Windows Administration Interview Questions|
|SSRS(SQL Server Reporting Services) Interview Questions||LINQ Interview Questions|
|Windows Presentation Foundation(WPF) Interview Questions||Advanced C# Interview Questions|
|Advanced jQuery Interview Questions||Asp Dot Net Mvc 4 Interview Questions|
|Windows Forms Interview Questions|
Windows Communication Foundation (WCF) Related Practice Tests
|VB.NET Practice Tests||C#. NET Practice Tests|
|Adv Java Practice Tests||SQL Server 2008 Practice Tests|
|ASP.NET Practice Tests||Windows Administration Practice Tests|
|SSRS(SQL Server Reporting Services) Practice Tests||LINQ Practice Tests|
|Windows Presentation Foundation(WPF) Practice Tests||Advanced jQuery Practice Tests|
|Windows Server 2012 Practice Tests|
Windows Communication Foundation (wcf) Tutorial
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.