SCM as Windows Service .NET Example
This example shows the SCM Edge Extension (SCMEXT) running as a Windows service. This service is installed automatically by the installer and is in the disabled state by default. A Windows service is not usually configured using command line properties, so the properties used to configure this service are stored in the registry. These settings must be configured before the service can be installed and started.
The SCM_service now uses a log4net configuration file called log4net-service.config . It logs to /opt/thingworx/scmlog.txt so when you start the service, look there for your log file. This directory should already be writable because that is where your offline message store is located. This file can be modified to put your log anywhere or to log to any output. It defaults to making a text file so that when starting your service, you know what it is doing.
Installation Steps
The following steps assume that you have run the installation program for the .NET SDK, which automatically installs the C SDK in the C:\Program Files\tw-c-sdk directory.
1. Log in to the Windows computer as an Administrator. You need to be an administrator to write to the registry later in this procedure.
2. Install the SCM Edge Extension.
3. Open the scm_service.reg file in a text editor. Set the values for each key, based on your environment. The meaning of each registry key follows:
name — The thingName of the Thing that you have created in ThingWorx to represent this device. This name will be the name of your device in the SCM console. The thing should have the following Thing Template and Thing Shapes applied:
TW.RSM.Template.AssetWithTunnelsAndFileTransfer Thing Template.
TW.RSM.SFW.ThingShape.Updateable Thing Shape.
PTC.Resource.Asset.SCMResourceThingShape Thing Shape. The value of this Thing Shape will be the name of your device in the SCM console
appKey — Generate an Application Key using ThingWorx Composer, encrypt it, and copy it to this key to act as the credentials that this service should use when it connects to the platform.
hostname — The name of the computer where your ThingWorx Platform is running. The value for this property is not a URL. It can be a DNS name, localhost, or a numeric IP address.
whitelist — A path to a CSV file listing the extensions and applications used to execute scripts which have this extension.
port — The port that your ThingWorx application is using on your server. Common values are 80, 8080, or 443
logfile — Do not use this parameter. You must use the log4net.conf file to set the location of this file.
extPath — This is the directory in which the service can find and load the libscmext.so or scmext.dll, that contains the C SDK SCM Edge Extension. This is the only directory from which any Edge Extension will be loaded.
stagingDirectory — A working directory where files will be uploaded to this device and from which scripts will be run. This directory must be writable from your service.
logLevel — You may reduce your log level before you start the service by setting this value. Acceptable values are listed below:
0 — None
1 — ERROR
2 — WARN
3 — INFO
4 — DEBUG (the default level)
5 — TRACE
Your log level will default to 0 if no value is given.
If you are using digital signing, you may have already added the validation parameter to this file. If you have not added it and are using digital signing, refer to How Do You Enable the SCM Service to Validate Digitally Signed Packages?
4. Save and close scm_service.reg.
5. If you are not logged in as Administrator, log out and back in as Administrator.
6. Open install.bat and edit the binpath= part of the example to point to the location of your scm_service.exe application.
7. Save, close, and then run install.bat as an Administrator using an Administrator Command Prompt. When the script finishes, you will see Thingworx SCM in the list of services in the Services window (on Windows 10, navigate to Start > Programs > Windows Administrative Tools > Services).
8. Make sure that your service has write access to the staging directory.
* 
Make sure that your service also has write access to the designated logging directory.
9. Create the directory listed in your stagingDirectory registry setting listed above.
10. Start your Thingworx SCM service using the Services admin tool.
11. To verify that the service is running correctly, check for a log file in the directory defined in your logFile registry setting.
Was this helpful?