Yes, that would work too. However you’d have to regenerate code after each change in the service interface.
So here is an example of a dynamic code-first service:
ModularServerTest2.zip (12.9 KB)
Solution contains 2 projects:
- ModularServerTest2 is a server application. It does not define any services.
Take a look at the Program.cs code (namely method LoadExternalAssemblies)
This method loads an assembly from a file (you’d need to change the path here to match the one you use), scans its public types for a class named Startup and then executes a method RegisterServices defined in this class.
ServiceLibrary is the class library containing service definition.
First, the Startup class.
Its RegisterServices method contains this code:
var rodlProvider = new RodlProvider();
rodlProvider.LoadConfiguration(); // In this method the RODL provider should load the service metainformation somehow, f.e. via some script
// Register RODL info provider
// Register Service invoker(s)
RemObjects.SDK.Server.Engine.ServiceManager.RegisterService("DynamicService", typeof(DynamicServiceActivator), new DynamicServiceActivator(), new DynamicServiceInvoker("DynamicRodlLibrary", "DynamicService", rodlProvider.GetServiceMethodDefinitions()));
Actually it loads service configuration (more on this later) and registers this configuration in server metainformation provider (aka RODL). Then it registers the service itself. The DynamicServiceInvoker created here is the heart of this dynamic service.
The DynamicServiceActivator class is just a dummy that does nothing. Its CreateInstance method implementation depends on your concrete implementation of script management code.
The RodlProvider class should gather dynamic service API (ie methods defined in the scripts) and turn it into a RODL definition code and a list of method definitions.
Currently this class contains hard-coded definitions of 2 methods.
The DynamicServiceInvoker class is the heard of this dynamic service. Its ServiceMethodInvoker method id invoked by Remoting SDK every time when server wants to execute a service method.
You will need to replace this console logging code with actual call to your script:
// TODO Invoke your script here. For now it is replaced with Console calls
for (Int32 i = 0; i < parameterValues.Length; i++)
// Fake result value instead of a real call
object result = "Dynamic method result";
Hope that helps