ComboService for .Net

In Delphi you can choose the ComboService when creating a RemoBjects Server, which is really good for development.
Is something like this possible for .Net?

regards
Paul

This works for me:

{$REGION Application Entry Point}
class method SomeServer.Main;
begin
  {$IFDEF DEBUG}
  var Service := new SomeServer;
  Service.OnStart(nil);
  System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
  {$ELSE}
  System.ServiceProcess.ServiceBase.Run(new SomeServer);
  {$ENDIF}
end;
{$ENDREGION}

You can now run and stop your service from Visual Studio IDE.

For the community. :wink:

I worked on a template for my projects, that’s working similar to the Delphi ComboService. It isn’t fully completed.

working part:

Run in VS or from commandline:

  • RO Service is starting as Application in a console window
  • full ability for debugging
    ServiceInstaller:
  • install / uninstall Service with “Service.exe -install or -uninstall”
  • start/stop the service from the Commandline

unfinished part:

  • the (inner) ServiceThread will not be started, when the Service is starting in Service-Mode

I’ve currently not enought time to finish this template.
Perheaps could someone else do this and RO could integrate the completed template in further versions of the SDK?

ROSDK.Net ComboService Template.rar (41.2 KB)

1 Like

Hello

Well, that’s why the http://wiki.remobjects.com/wiki/ApplicationServer_Class class has been introduced. The ApplicationServer class is designed to provide a common codebase and simplify development of RemObjects SDK and Data Abstract-based server applications. This class provides the following features:

  • 3 application run modes - GUI mode (WinForms or WPF), command-line interface or Windows Service
    Windows Service management (installation/deinstallation)
  • Optional Single Instance check
  • Extensible startup arguments parser

It is extensively used by the Data Abstract templates. As for pure SDK projects - give me some time and I’ll provide the similar template and its description (perhaps tomorrow).

1 Like

Hello again.

So, here is the 1st part where the application is created that can be used as a seed for a new projects: http://blogs.remobjects.com/blogs/antonk/2014/12/18/p7008

There will be a second part where the same app will be turned into a real VS template. Its draft is published below.

In this short article the server application template created in the previous article will be turned into a real Visual Studio template. The greater minds have already described the process in the MSDN article at http://msdn.microsoft.com/en-us/library/xkh1wxd8.aspx.

Some preparation work is needed before the project is turned into a real application template.

At first edit the AssemblyInfo.cs file so it will look as

using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;

//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("$projectname$")]
[assembly: AssemblyDescription("$projectname$")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("$registeredorganization$")]
[assembly: AssemblyProduct("$projectname$")]
[assembly: AssemblyCopyright("Copyright (c) $registeredorganization$ $year$")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]


[assembly: ComVisible(false)]

//
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: NeutralResourcesLanguageAttribute("")]

In the ServerApplication.cs file change the Application ID, Application Name and Service Name properties to

protected override string Identifier
{
    get
    {
        return "$guid1$";
    }
}

protected override string ServiceName
{
    get
    {
        return "$projectname$ Service";
    }
}

protected override string ApplicationName
{
    get
    {
        return "$projectname$";
    }
}

Open the MainService.cs in designer and set the ServiceName property to “$projectname$ Service“.

Open the ProjectInstaller.cs in designer and set the property ServiceName of the ServiceInstaller component to “$projectname$ Service” as well.

Then perform a project-wide replacement of string namespace ServerTemplate to string namespace $safeprojectname$

Save all changed files and issue menu command File -> Export Template. Export the project as a project template. Set the template name and description and press the Finish button.

Restart the Visual Studio. The template you just created will be available in the Visual Studio project templates.

PS If you really don’t want to follow all those boring steps then here is the download link for the template project. Download it, unzip and open in Visual Studio, then export as a project template.
Server.zip (66.6 KB)

1 Like

Do you plan to integrate your template as fixed part of future RO SDK.Net releases?

Yes, we’re currently working on this.

The ApplicationServer based ROSDK Server Template is part of the regular ROSDK.Net destribution in meantime.
I love this Template. It’s nice to have a Windows Service with is able to start as application with UI or optional in CLI Mode to get CW messages. Very well to work with that solution.

Is it possible that I add additional commandline parameters?
I’d like to add override parameters to individualize the serviceName and the serviceDiaplayName (perhaps the binding IP and TCP Port too) in --Install and --Uninstall mode.

Hello

Sure it is possible to add the additional parameters. You’d need to override the ProcessExtendedParameters method and check there the ExtendedParameters collection. At this moment application run mode is already known (ie is it just a simple app startup, service installation etc).
It is also possible to override the RunAsWindowsServiceInstallation method, but it is run AFTER the AssemblyInstaller does its work.

Regards

Overriding ProcessExtendedParameters and ExtendedParametersHelpText work fine so far.
I’ve the parsed custom parameters inside of my ApplicationServer instance. How Do I pass them to the service installer? Changing the ApplicationServers ServiceName and ApplicationName properties doesn’t affect the service installer. I haven’t found other properties or overrides that could match.

My goal is to have some install parameters that allows me to install multiple instances of the service on the same machine (individualize the ServiceName, Service Display Name, the TCP Port and perheaps the IP Service bindings). Port and IP could be done by updating the “.config”. The other ones should be passed to the service installer.

Hello

You need to parse them and then update the ServiceName property and corresponding properties of the service definition and service installer.

Don’t forget to override the IsCheckForOtherInstancesRequired property too - it should return false or you won’t be able to run more than a singe instance per host.

Regards

Hi,

IsCheckForOtherInstancesRequired is a good hint.
I’ve parsed my custom parameters. My problem is, when I call:
myservice -i -serviceName:“MyServiceInstance1” -serviceDisplayName:"My Service 1"
then the ApplicationServer calls the service installer and installs the service in a non virtual method.
I can’t override it to put my custom parameters into this process, to change the ServiceInstaller properties programmatically.

The installer code looks like

using (AssemblyInstaller installer = new AssemblyInstaller(Application.ExecutablePath, null))
{
    installer.UseNewContext = true;
    installer.Install(null);
    installer.Commit(null);

Your project contains separate WinService and WinService installer definitions. You needed to set the custom service name there in their installers (for both installation and later service startup).

Regards