New Remoting SDK server application - Best practices

Hello,

It’s been a couple of years since we had to create a new Remoting SDK server. But now the time has come. I’ve seen that a lot of things has changed when I created a Remoting SDK server, for starters a Code First one is new for me.

I have to create a Remoting SDK Windows service to do 2 things:

  • Send text messages (with an API with a bearer access token)
  • Poll for new incoming text messages

I’ve seen a new object of the type ApplicationServer is created in the Main and a Service is created.
[Service, StandardClassFactory]
public class TextMessageService : Service

Now my (maybe stupid) questions but I like to learn how this new setup works exactly before using it blindly:

  • When calling the SendTextMessage function of the TextMessageService from multiple clients, a new object of the TextMessageService type is always created (Why is that?), so caching my access token object in this ‘Service’ is a bad idea. What’s the best practice here? Caching it in a static class/object?
  • What’s the best practice of running a function periodically (every minute or so) in this type of Code First Remoting server? A timer, and if so, where do I declare en initialize it? I’m used of using the ServiceBase class with a timer, but in a Code First Remoting server no such class is created so I’m kinda lost :confused:

Thank you for helping me out.

Greetings.

Hello

This is the default behavior of Standard class factory. It creates a new service class instance for every incoming request.
If you need to share the same service instance between several call then you need to use the singleton class factory:

[SingletonClassFactory(SingletonBehavior.Multiple)]

https://docs.remotingsdk.com/Servers/Concepts/ClassFactories/

Assuming you are using the ApplicationServer boilerplate code then you can put your timer in a custom NetworkServer class: https://docs.remotingsdk.com/Servers/Concepts/ApplicationServer/ part Custom Network Server

Regards

Thanks. I will try it out.