Converting a .NET Server to Code-First

If you have an existing RODL-based server, you can easily convert this server to the new Code-First model, with a few simple steps.

Mind you, you don’t have to convert your servers to Code-First. RODL-based servers are still and will continue to be fully supported. Still, converting to the new model will make development so much easier going forward.

There are really just four steps involved in making the switch, all of them simple, and two of them automated by the IDEs:

  1. Adjust your existing Service implementations
  2. Convert your auxiliary types, such as structs and enums
  3. Remove your .RODL file and the auto-regenerating _Intf, _Invk and _Events files
  4. Add one statement of code to configure your server for Code-First

Adjusting Your Existing Services

While Remoting SDK has always auto-generated service stubs for you from the .RODL, once you add code to those files, it considers them “yours”, and the RO toolchain won’t touch them again. In the past, that was one of the annoyances when adding new methods to a service, as you had to edit both the .RODL and the implementation.

For that same reason, the IDEs won’t auto-convert your service implementations for you – but making the switch is easy. For each of your services, you just do three things:

  • Remove the InvokerClass and ActivatorClass Parameters from the Service attribute. This is the main step, and it tells the RO infrastructure that this service is now using Code-First.
  • Remove the service interface from the ancestor list.
  • To each of the methods you want to expose publicly, add the ServiceMethod attribute.

In essence, you’d go from something like:

[RemObjects.SDK.Server.ClassFactories.StandardClassFactory]
[RemObjects.SDK.Server.Service(Name = 'MyService', InvokerClass = MyService_Invoker.Type, ActivatorClass = MyService_Activator.Type]
MyService = public class(Service, IMyService)
    //...
end;
[RemObjects.SDK.Server.ClassFactories.StandardClassFactory]
[RemObjects.SDK.Server.Service(Name = 'MyService', InvokerClass = MyService_Invoker.Type, ActivatorClass = MyService_Activator.Type]
public class MyService : Service, IMyService {
    //...
}
@RemObjects.SDK.Server.ClassFactories.StandardClassFactory
@RemObjects.SDK.Server.Service(Name = 'MyService', InvokerClass = MyService_Invoker.Type, ActivatorClass = MyService_Activator.Type)
public class MyService : Service, IMyService
{
    //...
}

to just:

[Service, StandardClassFactory]
MyService = public class(Service)
    //...
end;
[Service, StandardClassFactory]
public class MyService : Service
{
    //...
}
@Service @StandardClassFactory public class MyService : Service {
    //...
}

Optionally you can also remove the StandardClassFactory attribute, as it is the default (if you switched to a different class factory, you would want to leave the attribute there, and you can also safely leave StandardClassFactory there, if you prefer).

You can also optionally remove the Name property from the Service attribute; if you do, the class name will be used as the name your service is published under.

Converting Auxiliary Types

Next, let's look at all the additional types you may have defined in the RODL to help your services. Enums, Structs, Exceptions or Arrays (although Arrays defined in RODL don’t really reflect in generated code).

In code, these all are contained in the _Intf file that you normally don’t touch, because it gets updated from the RODL when that changes. Since the RODL is going away, this auto-updating won’t happen anymore, so you are, in a way, “taking ownership” of these classes now.

You could just keep the _Intf file around, but there’s a ton of extra crud in there that you no longer need, and that would make it hard to maintain/update in the future. So really, it makes sense to clean that up, and we have automated that for you with a small IDE wizard that takes care of this and the next step. We’ll get to that in a second.

Remove the RODL and Auto-Generated Code

Once the auxiliary types are taken care of, the RODL file and the three source files generated from it (but not the services!) can simply be removed from the server project and deleted.

Bye bye RODL, it was nice to have known you.

The “Convert to Code-First” Wizard

To automate the above two steps, we’ve added a small helper wizard to the IDEs (Fire and Visual Studio).

Read more about how this works in:

When you invoke this conversion, the IDE will do two things:

  • It will generate a new code file in your projects’s language, named after the RODL file, but with a _RodlTypes suffix using your project's main language (Oxygene, C#, Swift, Java or Visual Basic). This file will contain all auxiliary types from your .RODL – in essence it will be the same as the previous `_Intf' file, but without all the extra crud.

  • It will remove the .RODL file, as well as _Intf, _Invk files from the project and delete them. These files will no longer be needed.

Once done, you can rename the _RodlTypes file to anything you like, or even move the types in it around into different source files (for example into the same file as their related service) as you see fit for the structure of your projects. These are now “your” types. If you need to make changes to them for new versions of our server, you simply change them in code.

These are now “your” types. If you need to make changes to them for new versions of your server, you simply change them in code.

Optionally, Configure Code-First

As a last step, there’s two lines of code you might want to add to your server, in order to control its name, and the namespace used internally by Code-First:

Add these lines among the startup code of your server:

if not RemObjects.SDK.Server.Configuration.Loaded then
    RemObjects.SDK.Server.Configuration.Load('MyProject' , MyProject.Server')
if (!RemObjects.SDK.Server.Configuration.Loaded)
    RemObjects.SDK.Server.Configuration.Load("MyProject" , "MyProject.Server")
if !RemObjects.SDK.Server.Configuration.Loaded {
    RemObjects.SDK.Server.Configuration.Load("MyProject" , "MyProject.Server")
}

The first string passed is the “name” of your server, as exposed externally (in the RODL that clients will download); the second string is the namespace that the Code-First engine will use for the helper types it generates under the hood at runtime.

If you don't add these lines, Remoting SDK will use reasonable defaults derived from the name of your assembly and the namespace your service classes are in. Alternatively, you can also set these values when creating your ApplicationServer instance.

Adding new Services

As you can imagine, adding new services to a Code-First server will be super easy with the new model. Simply add a new class, attach the Service attribute, and mark the methods you want published with ServiceMethod. Done. If you need new structs or enums, simply define them in code.

Converting a Server Partially

Note that you don’t necessarily need to convert all services to be Code-First in one go. You can start by converting some of your services and deleting them manually from the RODL, and leaving others RODL-based. Of course, in that case, you will want to delay removing the RODL file and converting the classes from the _Intf, until you're all done.

At runtime, Remoting SDK will take care of merging what’s in your RODL and what’s defined “Code-First” and make sure it all works together.