[英]How can I make service apps with Visual c# Express?
I have build an application to parse Xml file for integrating data in mssql database.我已经构建了一个应用程序来解析用于在 mssql 数据库中集成数据的 XML 文件。 I'm using Visual c# express.我正在使用 Visual c# express。 There's a way to make service with express edition or I a have to get Visual Studio to do it?有一种方法可以使用快速版提供服务,还是我必须让 Visual Studio 来做?
Absolutely you can.绝对可以。 You can even do it with csc
.你甚至可以用csc
来做。 The only thing in VS is the template . VS 中唯一的东西就是模板。 But you can reference the System.ServiceProcess.dll yourself.但是您可以自己引用 System.ServiceProcess.dll。
Key points:关键点:
ServiceBase
编写一个继承自ServiceBase
的类Main()
, use ServiceBase.Run(yourService)
在您的Main()
中,使用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)在ServiceBase.OnStart
覆盖中,生成完成工作所需的任何新线程等( Main()
需要立即退出,否则会被视为启动失败)Very basic template code would be:非常基本的模板代码是:
Program.cs :程序.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 : 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 : 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 (ie you can't use cron.exe /install
or some other command line argument. Instead you must use the .NET SDK's InstallUtil
: .NET 服务应用程序的安装方式与普通服务应用程序不同(即,您不能使用cron.exe /install
或其他命令行参数。相反,您必须使用 .NET SDK 的InstallUtil
:
InstallUtil /LogToConsole=true cron.exe
You could try Visual Web Developer Express along with the coding4fun developer kit library for web services (via managed code wrappers):-您可以尝试使用 Visual Web Developer Express 以及用于 Web 服务的 coding4fun 开发人员工具包库(通过托管代码包装器):-
http://www.microsoft.com/express/samples/c4fdevkit/default.aspx http://www.microsoft.com/express/samples/c4fdevkit/default.aspx
Express Edition can write and compile Windows Service projects, but it can't create them normally. Express版可以编写和编译Windows Service项目,但不能正常创建。 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.唯一简单的方法是在 Visual Studio 中创建一个新的服务项目,然后将项目文件复制到使用 Express Edition 的机器上。 After that you don't need Visual Studio any more.之后,您不再需要 Visual Studio。
There are 3 ways to accomplish this:有3种方法可以做到这一点:
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.最好的长期解决方案是让老板最终支付标准版或专业版的副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.