Example code snippets for JavaScript .net commandline server with client

As the wiki is still quite incomplete about this topic, here are some code snippets that might save others time researching what needs to be done. Mostly because it’s not always clear how things work in code. Most tips are around somewhere but these help you to get you started with your own server. It gives some more detail to the http://wiki.remobjects.com/wiki/Calling_RemObjects_SDK_Servers_from_JavaScript article, combined with a blog and connect topics.

class method TabellenAppServerMain.Main;
var
  lServerChannel: ServerChannel;
  lMessage: Message;
  lJavaMessage: JavaScriptHttpDispatcher; // add this line
begin
  Console.WriteLine('RemObjects SDK for .NET - Delphi Prism Command Line Server'); // autogenerated

  lServerChannel := new RemObjects.SDK.Server.ipHttpServerChannel();// autogenerated
  
  lMessage := new RemObjects.SDK.BinMessage(); // you need BOTH the JavaScript and BIN message items for communication (autgenerated)
  lJavaMessage := new JavaScriptHttpDispatcher(); 
  lJavaMessage.Path := '/js/'; // might be default value
  lJavaMessage.Server := lServerChannel as IHttpServer; // you need this cast to this interface.
// Do not use lServerChannel.Dispatchers.Add for the JavascriptHttpDispatcher, that will get you a runtime error with a casting problem.

  lServerChannel.Dispatchers.Add(lMessage.DefaultDispatcherName, lMessage);

// -- Rest of file is autogenerated

file index.html








var Channel = new RemObjects.SDK.HTTPClientChannel("http://" + window.location.host + "/BIN");
var Message = new RemObjects.SDK.BinMessage();
var Service = new TabellenAppServerService(Channel, Message);

function get_servertime() {

    Service.GetServerTime(

– rest of file autogenerated
You need to remotely get the RemObjectsSDK.js (or any other file) file, to overcome browser restrictions. The rest can be placed locally. But it might be good practice to get most of them from the server, so you can change them, and the third party only needs to manage a few files as possible.

I think will be a good idea to have a snippet library (perhaps in gist) to show single task examples. Is that simple task that I found hard to resolve, because Ro do a great job in the hard ones.

Thanks for your contribution, we’ll put it on the wiki.

I’ve extended How_to_Write_a_RemObjects_SDK_Client_(JavaScript) and How_to_Write_a_RemObjects_SDK_Server_(.NET) wiki articles
with your code snippet.

Also in next versions we’ve fix the API of Server channels, so it won’t be needed to cast the channel instance to set the ExtendedDispatcher.Server property.