I have build an application to parse Xml file for integrating data in mssql database. I\'m using Visual c# express. There\'s a way to make service with express edition or I a ha
Express Edition can write and compile Windows Service projects, but it can't create them normally. The only easy way is to create a new service project in Visual Studio, and then copy the project files to the machine with Express Edition. After that you don't need Visual Studio any more.
There are 3 ways to accomplish this:
However you'll still run into some difficulties such as if you want to rename your project or not have to repeat this for every new service. The best long term solution is to get the boss to finally pay for a copy of Standard or Professional edition.
You could try Visual Web Developer Express along with the coding4fun developer kit library for web services (via managed code wrappers):-
http://www.microsoft.com/express/samples/c4fdevkit/default.aspx
Absolutely you can. You can even do it with csc
. The only thing in VS is the template. But you can reference the System.ServiceProcess.dll yourself.
Key points:
ServiceBase
Main()
, use ServiceBase.Run(yourService)
ServiceBase.OnStart
override, spawn whatever new thread etc you need to do the work (Main()
needs to exit promptly or it counts as a failed start)Very basic template code would be:
Program.cs:
using System;
using System.ServiceProcess;
namespace Cron
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
System.ServiceProcess.ServiceBase.Run(new CronService());
}
}
}
CronService.cs:
using System;
using System.ServiceProcess;
namespace Cron
{
public class CronService : ServiceBase
{
public CronService()
{
this.ServiceName = "Cron";
this.CanStop = true;
this.CanPauseAndContinue = false;
this.AutoLog = true;
}
protected override void OnStart(string[] args)
{
// TODO: add startup stuff
}
protected override void OnStop()
{
// TODO: add shutdown stuff
}
}
}
CronInstaller.cs:
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
[RunInstaller(true)]
public class CronInstaller : Installer
{
private ServiceProcessInstaller processInstaller;
private ServiceInstaller serviceInstaller;
public CronInstaller()
{
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.StartType = ServiceStartMode.Manual;
serviceInstaller.ServiceName = "Cron"; //must match CronService.ServiceName
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
And a .NET service application is not installed the same way as normal service application (i.e. you can't use cron.exe /install
or some other command line argument. Instead you must use the .NET SDK's InstallUtil
:
InstallUtil /LogToConsole=true cron.exe
According to this MSDN article you don't have the project template for a service. But I'm pretty sure that if you know what the template does for you, you can create and compile a service.