How can I make service apps with Visual c# Express?

后端 未结 4 2055
执笔经年
执笔经年 2021-01-30 07:32

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

相关标签:
4条回答
  • 2021-01-30 08:03

    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:

    • Go to a machine with Visual Studio and create the project
    • Google an online tutorial for creating services and download the project source code
    • Download and install a 90 day trial version of Visual Studio to create the project

    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.

    0 讨论(0)
  • 2021-01-30 08:04

    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

    0 讨论(0)
  • 2021-01-30 08:12

    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:

    • write a class that inherits from ServiceBase
    • in your Main(), use ServiceBase.Run(yourService)
    • in the 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)

    Sample Code

    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
    

    Resources

    • Creating a Windows Service in .NET by Mark Strawmyer
    • Writing a Useful Windows Service in .NET in Five Minutes by Dave Fetterman
    • Installing and Uninstalling Services
    • Walkthrough: Creating a Windows Service Application in the Component Designer
    0 讨论(0)
  • 2021-01-30 08:20

    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.

    0 讨论(0)
提交回复
热议问题