2017-05-31 98 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" } } }

希望這會有所幫助。