Home > WCF > Steps to create and deploye Windows Service

Steps to create and deploye Windows Service

To create and deploy the WCF Service as the Windows Service in step by step. The following article describe about.

  1. Steps to Create Windows Service using WCF
  2. Steps to Deploy Windows Service using installutil.exe

Steps to Create Windows Service using WCF

  • Create new project using VS2012, Select File > New Project from the Menu.

New Project

  • Select Windows Service template from New Project dialog.

Create Winodw Service

  • Right click on designer and select Property and set ServiceName and Name

ServiceInstaller Property

  • Drag an EventLog component to the designer, from the Components section of the Toolbox.

Drag and Drop EventViewer in Design screen

  • Press F5 and use the below code.

Sample Code

public MyFirstWindowsService()
        {
            InitializeComponent();
            if (!System.Diagnostics.EventLog.SourceExists("WSMessage"))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    "WSMessage", "NewWSLog");
            }
            eventLog1.Source = "WSMessage";
            eventLog1.Log = "NewWSLog";

        }

        protected override void OnStart(string[] args)
        {
            string str = "Service Start at :" + DateTime.Now.ToString();
            eventLog1.WriteEntry(str);

        }

        protected override void OnStop()
        {
            string str = "Service Stopped at :" + DateTime.Now.ToString();
            eventLog1.WriteEntry(str);
        }

Now Windows service is ready and it is ready to write message to Event handler while start and stop event is triggered.

Steps to Deploy Windows Service using installutil.exe

  • Right-click Service1.cs and select View Designer from Solution Explorer

Select Property for Service.cs file from solution explorer

  • Right-click, and then click Add Installer in View Designer Screen. The two installers is added to your project inside ProjectInstaller.cs screen.
  • Right click on serviceInstaller1 from ProjectInstaller.cs and make sure the Service Name property is set to MyFirstWindowsService and Start Type property is set to Automatic.

Select process PropertyServiceInstaller Property

  • Right click on serviceProcessInstaller1 from ProjectInstaller.cs and Set the Account property to LocalSystem. This will cause the service to be installed and to run on a local service account.

ServiceProcessInstallerProperty

  • Build the project

Steps to install

  • Open the Developer Visual Command Prompt in Administrator mode
  • installutil.exe C:\MyNewService\bin\MyNewService.exe
  • Open the Control panel and check the ‘MyNewService’ is started else start service.
Advertisements
Categories: WCF Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: