How to write a Server (.NET)
Note: This article is outdated.
This article explains how to create your first Remoting SDK server. There is an associated article (How to write a Remoting SDK Client (.NET)) which shows how to build a client to access this server.
Note: if you are also interested in the Delphi version of these articles, see How to write a Remoting SDK Server (Delphi) and How to write a Remoting SDK Client (Delphi).
There is also How to write a Remoting SDK Client (JavaScript).
Selecting the server type
The first step consists in selecting the server type you want to create. From the Visual Studio IDE, select the File -> New -> Other
menu item. This is what you will be presented with:
In this example, we will create a simple Windows Forms Server
Executable. This is the simplest type of server that you can create and it does not require any web server or additional configuration to run. Select Windows Forms Server
and click OK
. You will see the New Remoting SDK Server
dialog:
Selecting advanced project options
Click on the Advanced Project Options
button to see a dialog with all server options. This allows you to enter basic options such as the names of your project and service library, the channel type and the message type you wish to use:
- Uncheck
Also create a matching Client Application
Normally, you will want to create a client application too, but as you will need to know how to do these simple steps yourself for creating additional clients, we show this separately in the How to write a Remoting SDK Client (.NET) article.
Although we don't need to change anything else here for this project, this is what each of other options mean:
Template Location
: RemObjects server projects are template based. If you look under<VS folder>\Common7\IDE\ProjectTemplates\<language>\Remoting SDK
, you will find a number of folders containing templates.Project Name
: the name of the project that will be created.Project Location
: the folder where your project will be saved.Library Name
: each Remoting SDK server can host multiple services. The library name is stored inside the RODL and will be used for the generated Intf and Invk source files.Service Name
: the name of the first service created for you.Server Channel
: Remoting SDK servers can serve clients using multiple communication protocols. This is where you choose which one to use by default. Keep in mind that you will be able to add additional channels later.- Message: RemObjects servers can be accessed using different messaging protocols. This is where you choose which one to use by default.
Click on OK
to create your solution.
Activate your server
Your project is now created and the main form is displayed inside Visual Studio:
At the bottom of the form designer window you will see two components which correspond to the Server Channel Class
and Message Class
that we selected in the previous dialog.
Click on the ServerChannel
component to see that its Active
property is set to TRUE
(the default):
RODL file: proxy, stub and implementation files
If you look closely at the Solution Explorer, you will notice a red icon pointing to the ROWindowsFormsServer.RODL
file. RODL (RemObjects Definition Language) files contain the definitions of all services and data types exposed by your server.
You can view or edit these files using the Service Builder utility.
Launch it by double clicking the RODL file inside the Solution Explorer or by selecting Edit Service Library
from the Remoting SDK menu:
As you can see, this RODL contains the definition of one service and this contains two (default) methods: Sum
and GetServerTime
.
There's no need for you to add or modify anything at this point. Simply close the Service Builder and look at how the solution has changed:
Every time you edit the RODL file using the Service Builder, the Visual Studio IDE will parse the RODL file and update or create the following files:
<LibraryName>_Intf
: this file contains the proxy code that will be used by the client to access the remote services.<LibraryName>_Invk
: this file contains the stub code that is necessary (server side) to invoke the methods of the services without using reflection, thus providing better performance.<ServiceName>_Impl
: this file will be generated once only per service and will never be touched thereafter. It contains the implementation of your service.
Open the ROWindowsFormsServerService_Impl.cs
file and provide an implementation for the Sum
and GetServerTime
methods as shown below:
public virtual int Sum(int A, int B)
{
return A + B;
}
public virtual System.DateTime GetServerTime()
{
return DateTime.Now;
}
You can now compile and launch your server by pressing F5
.
Testing the server
This is how the server looks once it's started:
Now that your server is running, it's time to check if it's working. Open Internet Explorer and type in the following URL: http://localhost:8099/BIN
You will see the following XML document displayed:
Thats it! The server is successfully running and ready to be used by Remoting SDK clients. All we had to do was to write two simple lines of code.
Note: if your browser did not display the XML document shown in the screenshot above, it is either because you did not set the property ROServer.Active to TRUE or because you typed in the wrong URL.
Now it's time to create a client to access this service. See article How to write a Remoting SDK Client (.NET).
Enabling JavaScript access at the server
Drop the JavaScriptHttpDispatcher component onto the server form or data module and connect its Server
property to your server channel component. Please pay attention to the default values of its properties: DefaultFile
property is set to index.html
, Folder
property is set to .\html
and Path
property is set to /js/
. This article assumes that these values are left untouched.
Here is a short example of server components configuration:
lServerChannel := new RemObjects.SDK.Server.IpHttpServerChannel();
lMessage := new RemObjects.SDK.BinMessage();
var lJsDispatsher := new JavaScriptHttpDispatcher(
DefaultFile := 'index.html', // default value
Path := '/js/', // default value
Folder := 'html', // default value
Server := lServerChannel // binding to server channel
);
Note: The JavaScriptHttpDispatcher component turns your RemObjects server into web server, but nothing prevents you from putting your application and library files to any other web server. In this case you won't need a JavaScriptHttpDispatcher dispatcher, instead you'll need to enable cross-origin access (CORS) support in the server channel by setting its SendCrossOriginHeader
property to true
and handling its OnSendCrossOriginHeader
event if needed.
If you are using JsonMessage message type then you have to set to true
its WrapResult
, SessionIdAsId
and SendExtendedException
properties.
For the BinMessage message type its UseCompression
property should be disabled because JavaScript client doesn't support BinMessage compression yet.
Any other message types are not supported.
The server is ready, now to How to write a Remoting SDK Client (JavaScript).