0

我正在使用 worklight 6.2 并构建一个 blackberry 6 /7 示例应用程序,但我面临连接问题。

由于连接问题,我无法调用适配器,并且每次我都收到来自适配器的响应失败。

我的代码片段如下

配置文件

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0" rim:backButton="exit">  
    <name>bb67</name>  
    <description>bb67</description>  
    <author email="application author's e-mail">application's author</author>  
    <feature id="worklightFeature" required="false" version="1.0.0"/>  
    <feature id="blackberry.ui.dialog" version="1.0.0"/>  
    <feature id="blackberry.ui.menu" version="1.0.0"/>  
    <feature id="blackberry.invoke" version="1.0.0"/>  
    <feature id="blackberry.invoke.BrowserArguments" version="1.0.0"/>  
    <feature id="blackberry.identity" version="1.0.0"/>  
    <feature id="blackberry.app" version="1.0.0"/>  
    <feature id="blackberry.app.event" version="1.0.0"/>  
    <access subdomains="true" uri="*"/>  
    <content src="www/skinLoader.html"/>  
    <icon rim:hover="false" src="icon.png"/>  
    <rim:loadingScreen backgroundImage="" foregroundImage="splash.png" onLocalPageLoad="false" onFirstLaunch="true"/> 
</widget>

索引,html

<!DOCTYPE HTML><html>
    <head>
        <meta charset="UTF-8">
        <title>bb67</title>
        <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" name="viewport">
            <!--
                <link rel="shortcut icon" href="images/favicon.png">
                <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> 
            -->
        <link href="worklight/worklight.css" rel="stylesheet">
        <link href="css/main.css" rel="stylesheet">
        <script>
        // Define WL namespace.
        var WL = WL ? WL : {};
        /**
         * WLClient configuration variables.
         * Values are injected by the deployer that packs the gadget.
         */
         WL.StaticAppProps = {
   "APP_DISPLAY_NAME": "bb67",
   "APP_ID": "bb67",
   "APP_SERVICES_URL": "http:\/\/192.168.0.222:10080\/bb67\/apps\/services\/",
   "APP_VERSION": "1.0",
   "ENVIRONMENT": "blackberry",
   "LOGIN_DISPLAY_TYPE": "embedded",
   "WORKLIGHT_PLATFORM_VERSION": "6.2.0.01.20141027-1531",
   "WORKLIGHT_ROOT_URL": "http:\/\/192.168.0.222:10080\/bb67\/apps\/services\/api\/bb67\/blackberry\/"
};
</script>
        <script src="worklight/wljq.js"></script>
        <script src="worklight/worklight.js"></script>
        <script>window.$ = window.jQuery = WLJQ;</script>
    </head>
    <body style="display: none;">
            <!--application UI goes here-->
            Hello Worklight<input onclick="msiteCall()" type="button" value="Call Adapter">
            <script src="js/initOptions.js"></script>
            <script src="js/main.js"></script>
            <script src="js/messages.js"></script>
    </body>
</html>

main.js

/* JavaScript content from js/main.js in folder common */
function wlCommonInit(){
    /*
     * Use of WL.Client.connect() API before any connectivity to a Worklight Server is required. 
     * This API should be called only once, before any other WL.Client methods that communicate with the Worklight Server.
     * Don't forget to specify and implement onSuccess and onFailure callback functions for WL.Client.connect(), e.g:
     *    
     *    WL.Client.connect({
     *          onSuccess: onConnectSuccess,
     *          onFailure: onConnectFailure
     *    });
     *     
     */

    // Common initialization code goes here
      WL.Client.connect({
                onSuccess: function onConnectSuccess(res){
                        alert('Connection Success '+res);
                },
                onFailure: function onConnectFailure(res){
                        alert('Connection Failure '+res);
                }
         });
}

/* JavaScript content from js/main.js in folder blackberry */
// This method is invoked after loading the main HTML and successful initialization of the Worklight runtime.
function wlEnvInit(){
    wlCommonInit();
    // Environment initialization code goes here
}
var timeout = 30000;
function msiteCall(){
    alert('Inside call');

    var invocationData = {
            adapter : "msiteAdap",
            procedure : "getStories",
            parameters : [],
            compressResponse : true
    };
    //WL.Logger.debug('invoke msg  '+invocationData, '');
    WL.Client.invokeProcedure(invocationData, {
        onSuccess : function succ(){alert("Success...");},
        onFailure : function fail(){alert("Failure...");},              

    });
}

请建议是否缺少任何东西。我正在使用 webworks 来构建项目。我使用以下命令来构建 cod 文件。

bbwp C:\myapp\myarchive.zip -d -o C:\myapp\output 

下面是工作灯项目生成的结构。

在此处输入图像描述

请建议worklight中是否有任何带有webwork项目的正确文档。

4

1 回答 1

0

从评论中可以看出,在物理设备中运行应用程序时已解决此问题。该设备通过 WiFi 连接到服务器运行所在的同一网络。

剩下的问题是在 BlackBerry Simulator 中运行应用程序时,它实际上在 VMWare Fusion 中运行。

如果该 VM 无法访问您的本地网络,则在其中运行的应用程序也将无法连接到服务器。

建议:

  • 浏览虚拟机设置并确保正确设置以访问您的本地网络
  • 您可以通过在其中打开浏览器来检查这一点,看看您是否能够访问服务器的 Worklight 控制台
于 2015-09-26T05:37:46.883 回答