2017-05-31 96 views
1

我在Wakanda Studio(Angular 4项目)的modules文件夹(后端)中创建了一个JS文件,我启用了RPC并将其添加到permissions.waPerm文件中。Wakanda RPC客户端

当我检查localhost:8081/rpc-proxy/myRpc /我可以看到该方法存在,但我不知道如何访问它的客户端,因为每个关于它的文档都谈论如何使用Prototyper或GUI Designer Wakanda工作室,但这两个在当前版本的工作室中不再存在。

有什么想法?

回答

1

在Angular 4或除WAF之外的任何客户端框架。可以使用HTTP POST将JSON-PRC服务作为应用程序中的外部模块进行访问。

根据文档,如果您想从任何外部页面调用Wakanda RPC方法,则需要在HTML页面中添加一个“脚本”标记。例如:

<script type="text/javascript" src="/rpc-proxy/myRPC?namespace=myRPC"></script> 

WAFmyRPC将成为您的角度应用可用。 然后,你所要做的就是使用命名空间myRPC(几处调整)。

这里是我做了什么得到它的工作:

  1. 添加脚本的index.html

  2. 然后,在你app.component声明WAF和myRPC。 TS:

    declare var myRPC: any; declare var WAF: any;

  3. 做的好办法到WAF对象:

    WAF.core = {restConnect:{baseURL : "${window.location.origin}"}}; WAF.config = {enableFilePackage:true}

  4. 呼叫myRPC使用documented API

    myRPC.isEmptyAsync({ 'onSuccess': function(result) { console.log(result); }, 'onError': function(error){ console.log('An error occured: '+error); },
    'params': [4, 5]})

  5. 更新 “proxy.conf.json”:用以下JSON对象:

    { "/rest/*": { "target": "http://127.0.0.1:8081", "secure": false, "ws": true, "headers": { "host": "127.0.0.1:8081", "origin": "http://127.0.0.1:8081" } }, "/rpc-proxy/*": { "target": "http://127.0.0.1:8081", "secure": false, "ws": true, "headers": { "host": "127.0.0.1:8081", "origin": "http://127.0.0.1:8081" } }, "/rpc/*": { "target": "http://127.0.0.1:8081", "secure": false, "ws": true, "headers": { "host": "127.0.0.1:8081", "origin": "http://127.0.0.1:8081" } } }

希望这会有所帮助。