Javascript access to RO server?

Server.zip (1.7 MB)
I have created a simple testserver. Calling the Sum() method is working OK, however when I cal a method that returns a struct, the call fails:

        var Channel = new RemObjects.SDK.HTTPClientChannel("http://localhost:5274/handler.ashx/binmessage");
        var Message = new RemObjects.SDK.BinMessage();
        Message.UseCompression = false;
        var Service = new SampleService(Channel, Message);

        Service.GetUser(
            function (result) {
                alert(result);
            },
            function (msg) {
                alert('Error');
                alert(msg.getErrorMessage())
            });
        alert('Call completed');

This code first shows ‘Call completed’, then ‘Error’ and then an empty message (msg.getErrorMessage() is empty). I tried both BinMessage and JsonMessage.

Server sample (C#. ASP.NET): https://lynxdiagnostics.blob.core.windows.net/backup/Server.zip
Client sample: https://lynxdiagnostics.blob.core.windows.net/backup/Client.zip

Fiddler shows (see Image) that the server correctly sends a response to the client.
Cross origin headers are handled inside Web.config.

What could be the problem? Thanks for any support you can give…
Kees Vermeulen

1 Like

Hello

Thanks for the testcase. Actually it works perfectly after one minor bug is fixed in the code.

Your client app’s Scripts contain files WebApplication1\Scripts\SampleLibrary_intf.js and WebApplication1\Scripts\ADatoServiceLibrary_intf.js

Both these files define a structure named User

__namespace.User.prototype = new RemObjects.SDK.ROStructType();
__namespace.User.prototype.constructor = __namespace.User;
RemObjects.SDK.RTTI["User"] = __namespace.User;

When a server sends back a structure named User the client tries to read it from the stream. However server sends similar structure defined in the SampleLibrary_intf.js file while clients tries to deserialize it as a much more complex structure defined in ADatoServiceLibrary_intf.js. This results in the error you see.

To get the sample working I just removed the file WebApplication1\Scripts\ADatoServiceLibrary_intf.js from the client app sample to resolve the naming conflict.

Regards

Tjee, such a simple solution. Thanks a lot.