# Service Hoster

{% hint style="info" %}
The TimeLine Service Hoster is an independent Windows service which is able to host sub-services which can easily interact with the TimeLine ecosystem. Please note that the term sub-service is used very loosely and is not an actual service, it rather is an AppDomain running in the Service Hoster service. The services are started inside a headless TimeLine client. The client also performs a login to provide access to all non visual TimeLine features like `xTransactions`, `BusinessObjects` and the `Sql` class.
{% endhint %}

### Configuring the Service Hoster

The Service Hoster loads a config called `services.json` from the TimeLine servers config directory. To edit it the visual editor inside the TimeLine Server app can be used. To access it right click on the TimeLine Service Hoster and choose `Config`.

<figure><img src="https://2522353545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXf5GuikRIHooatf_sm%2Fuploads%2FgA29BlsYriV2CD5UKa2i%2FScreenshot%202023-07-04%20094700.png?alt=media&#x26;token=15ed0530-18df-460e-ac8f-28bb3223ab85" alt=""><figcaption><p>Example config</p></figcaption></figure>

The service name must be unique. The assembly must not contain a path. It must just be the assembly name including the file ending. The class must be the assembly qualified name of the type (full namespace plus class name). Root path and custom path are optional overrides for the service. The mandants for which the service will be started for can be configured using one of the edit mandants buttons.&#x20;

<figure><img src="https://2522353545-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXf5GuikRIHooatf_sm%2Fuploads%2FHMhE1mtmJlmhq0zkGMDn%2FScreenshot%202023-07-04%20141954.png?alt=media&#x26;token=529e9a6a-4008-4dc1-8b2a-8f2d0ecb3045" alt=""><figcaption><p>Example mandants</p></figcaption></figure>

{% hint style="warning" %}
Please note, only the Mandant name is required here.&#x20;

If no username and password are provided, the cached credentials will be used.&#x20;

**Please make sure you perform a initial login on the server mandant in order to cache the credentials!**
{% endhint %}

It is advised to create a new user to run the service. The service will create a session and block the user but it will not use a workplace license.

The assembly is resolved using the `ObjectFactory`. The default root is `[TimeLine server installation root]\ServicesRoot`. The custom path is set in the `TLX.ini` for each mandant. These paths can be overridden for each service using the `Root path` and `Custom path` properties.

### Logging

The Service Hoster has its own log file which is located in `[TimeLine server installation root]\Logs\ServiceHoster`. Each hosted service has its own sub directory containing the services log files.

### Creating a custom service

Add a reference to `TimeLine.Services.Framework` to the project that will contain the service. The service class must inherit from `TimeLine.Services.Framework.TlService`.&#x20;

The `TlService` class contains the property `Log` which should be used to log any information needed to the services log file. It also has 3 abstract methods which must be implemented.&#x20;

When the service starts the `Init()` method is the first method that is called. Afterwards the login is performed. After a successful login the `Start()` method is called. When the service stops the `Stop()` method is called.

### Debugging issues with the service hoster

You can check the log files associated with the service hoster and hosted services to find more information about potential issues. These log files are located in the `TLServer\Logs\ServiceHoster` directory.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tldocs.gitbook.io/documentation/framework/server-side-logic-and-customization-v16+/service-hoster.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
