Enabling JavaScript Access on 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: the DefaultFile property is set to index.html, the Folder property is set to .\html and the Path property is set to /js/. This article assumes that these values are left untouched.

Here is a short example of the server components configuration:

lServerChannel := new RemObjectsSDKServerIpHttpServerChannel();
lMessage := new RemObjectsSDKBinMessage(); var lJsDispatsher := new JavaScriptHttpDispatcher(
DefaultFile := 'indexhtml', // 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 a 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, you have to set its WrapResult, SessionIdAsId and SendExtendedException properties to true. For the BinMessage type, its UseCompression property should be disabled, because JavaScript clients don't support BinMessage compression yet.

Other message types are not supported.

Interface file generation

Open the server's RODL file. In the RAD Studio click RemObjects menu item. In visual Studio just double-click the .RODL file in Solution Explorer.

The Service Builder will start. Once it is up click CodeGen, then hit Save code button and save generated JavaScript interface file as NewLibrary_intf.js.

Setting up the client application

In the folder where the server executable file is located, create a subfolder and name it html. Put NewLibrary_intf.js there. Also create html file and save it as index.html to this subfolder.

<html>
<head>
</head>
<body>
<h1>RemObjects SDK client</h1>
</body>
</html>

Time to test. Run the server and open http://localhost:8099/js/ in the browser.

Accessing the server

To access the server, the library and generated interface file should
be included into index.html. Also we're adding a link to call method
and a textarea to print results there.

Finally, some coding. We need a channel instance to transfer
requests and responses back and forth, we need a message instance to
encode/decode data and a service proxy instance to hide most
implementation details from us. Proxy method takes callback function as a
parameter and calls it when result has been received from the server.

<html>
<head>
<script type="text/javascript" src="RemObjectsSDK.js"></script>
<script type="text/javascript" src="NewLibrary_intf.js"></script>
</head>
<body>
<h1>RemObjects SDK client</h1>
<a href="#" onclick="getTime();">Get time</a><br />
<textarea id="log" rows=10 cols=60></textarea>
<script type="text/javascript">
var channel = new RemObjects.SDK.HTTPClientChannel("http://" + window.location.host + "/BIN"); //IE users use JSON
var message = new RemObjects.SDK.BinMessage();
var service = new NewService(channel, message); function getTime() {
service.GetServerTime(function(result) {
document.getElementById("log").value += result + "\n";
}, RemObjects.UTIL.showError);
}
</script>
</body>
</html>

Note: Internet Explorer doesn't support posting binary data, so JSONMessage should be used. Moreover, in some versions/modes it doesn't support JSON too, then please use any third-party JSON implementation. Most known one - https://github.com/douglascrockford/JSON-js

Conclusion

As you can see, with RemObjects SDK for JavaScript it takes five lines to prepare and another five lines to actually call remote service and get response data from the server.

http://old.wiki.remobjects.com/wiki/How_to_Add_a_RemObjects_SDK_for_JavaScript_Web_Client_to_your_Server_(.NET)

js调用ro的webservice的更多相关文章

  1. JS调用WebService,发布到IIS,网页提示WebService未定义[已解决]

    VS2013中,JS调用WebService,一直运行正常.部署到WindowsServer2008之后,在网页中访问,始终提示网页中有错误,点开之后发现是WebService未定义. 于是上网查解决 ...

  2. Js 调用 WebService 实例

    Html页面代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/ ...

  3. JS调用webservice服务

    webservice服务 webservice服务代码 using System; using System.Collections.Generic; using System.Linq; using ...

  4. asp.net 练习 js 调用webservice

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  5. NET-使用Js调用WebService

    注:JsWebServiceObject 此类是我做测试示例时为了测试js是否能调用webService中的复合类型而单独新建的一个类 此类中只有名字与年龄的属性. 最近身边的一个朋友做项目,其中有一 ...

  6. js调用soapWebService服务

    js调用soapWebService服务 什么是 SOAP? SOAP 指简易对象访问协议 SOAP 是一种通信协议 SOAP 用于应用程序之间的通信 SOAP 是一种用于发送消息的格式 SOAP 被 ...

  7. jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子

    一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...

  8. Jquery利用ajax调用asp.net webservice的各种数据类型(总结篇)

    原文:Jquery利用ajax调用asp.net webservice的各种数据类型(总结篇) 老话说的好:好记心不如烂笔头! 本着这原则,我把最近工作中遇到的jquery利用ajax调用web服务的 ...

  9. js调用跨域

    web aapi 初体验 解决js调用跨域问题   跨域界定 常见跨域: 同IP不同端口: http:IP:8001/api/user     http:IP:8002/api/user 不同IP不同 ...

随机推荐

  1. Android中静态变量的生命周期

    静态变量的生命周期,起始于类的加载,终止于类的释放.什么时候类会加载呢?我们知道,在app打开时,会创建一个进程,然后初始化一个dvm的实例,负责类的加载释放 和 垃圾回收等.换句话说,在进程创建之后 ...

  2. Linux I2C设备驱动编写(一)【转】

    本文转载自:http://blog.csdn.net/airk000/article/details/21345457 在Linux驱动中I2C系统中主要包含以下几个成员: I2C adapter 即 ...

  3. AD、DNS、DHCP、IIS、WINS的形象定义及关系

    AD-实际是就是一个包括所有信息的数据库,和现实生活中就将其比作派出所,所有的信息都要进入他那的数据库当中(包括人员姓名(计算机名.账号.密码等) DNS就是建立起关联起好记忆的名称,比如你家的位置用 ...

  4. Java开源JSP标签库

    01displytag 与Struts结合使用最出名的一个tag主要是显示表格数据很漂亮.完善. 02cewolf tag 用来在web上显示复杂图形报表的一个jsp tag. 03Loading T ...

  5. PCB SQL SERVER 邮箱配置与发邮件

    一.开启SQL SERVER发邮件功能 --开启发邮件功能 reconfigure with override go reconfigure with override go 二.邮箱配置 1.代码创 ...

  6. 洛谷P1330 封锁阳光大学(二分图染色)

    P1330 封锁阳光大学 题目描述 曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街.河蟹看到欢快的曹,感到不爽.河蟹决定封锁阳光大学,不让曹刷街. 阳光大学的校园是一张由N个点构 ...

  7. P3309 [SDOI2014]向量集

    传送门 达成成就:一人独霸三页提交 自己写的莫名其妙MLE死都不知道怎么回事,照着题解打一直RE一个点最后发现竟然是凸包上一个点求错了--四个半小时就一直用来调代码了-- 那么我们只要维护好这个凸壳, ...

  8. centos安装 memcached

    .安装 yum -y update yum install -y libevent libevent-devel yum install -y memcached 2.配置 vi /etc/sysco ...

  9. linux top 的用法

    本篇博文主要讲解有关top命令,top命令的主要功能是查看进程活动状态以及一些系统状况. TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终 ...

  10. Nginx 配置https请求

    通过阿里云生成指定的https证书文件xxxx.key 和 xxxx.pem文件 在阿里云上申请的https证书的是pem格式,转成cer 先在终端cd到文件目录下 然后 openssl x509 - ...