Console example to Windows Service

3 posts / 0 new
Last post
Offline
Last seen: 6 months 1 week ago
Joined: 06/03/2019
Posts: 2
Console example to Windows Service

I have a C# application that is very similar to the HelloWorld xml dynamic console application.

I have programmed a /install option to install the console application (and uninstall) as a Window Service with Project Installer.  That all appears to work great and the service does run up to the a point (logging framework working).

However, when I run the service the application fails at first reference to DDS object..i.e. to create the participant from the configuration file

                /* To customize QoS, use
                the configuration file USER_QOS_PROFILES.xml */
                if (this.participant == null)
                {
                    this.participant = DDS.DomainParticipantFactory.get_instance().
                            create_participant_from_config(
                                            "MyParticipantLibrary::PublicationParticipant");
                    if (this.participant == null)
                    {
                        log.Error("! Unable to create DDS domain participant");
                        return;
                    }
                }

It runs okay in console mode.  Only as a service does it fail.  I'm using a logging framework as well and it references that external its own dll okay.

I have tried changing the security parameters on the USER_QOS_PROFILE.xml file to everyone as well with no success.

Any ideas or suggestion is much appreciated.

 

 

 

Organization:
Offline
Last seen: 6 months 1 week ago
Joined: 06/24/2016
Posts: 7

Hello,

In my experience this seems to be because the working directory used when running as a service is not the directory containing the service executable. Therefore DDS does not find the User QoS File when running as a service, but it will when running directly as an executable.

Assuming that the User QoS Profiles file is in the same directory as the actual service executable, then you will need to find the name + path of the executing assembly or module using (e.g.) GetExecutingAssembly (.NET) or GetModuleFileName (Win32), and use that to construct the path to the User QoS Profiles file.

Then set the DDSDomainParticipantFactoryQoS.profiles.url_profile. You may need to set ignore_user_profile to true as well.

As far as I know or understand you will need to do this before creating any domain participants.

I'm sorry, I can't give you any example code.

Offline
Last seen: 6 months 1 week ago
Joined: 06/03/2019
Posts: 2

Just a quick update. 

It does look like you suggested that it was not finding the xml file. 

I logged the assembly path and it all looks to be correct.  It was the same for both console mode and service.

I was able to figure out that it was not finding the file by just trying a few things.  I move the USER_QOS_PROFILE.xml over to the Windows\System32 directory and it work successfully.   I'm not sure why it is looking there instead of the working path of the service (where the exe is located).  

Looking now at your last few statements to set path.

Thanks for your help.