调用WL.Client.invokeProcedure时遇到错误

时间:2013-05-01 18:28:10

标签: iphone dojo ibm-mobilefirst

我正在调用一个worklight适配器并对外部服务进行调用。执行worklight方法WL.Client.invokeProcedure(invocationData,options)时,调试区域出现以下错误:

  

'null'不是'in'“

的有效参数

下面是我的适配器调用实现,不知道我在哪里犯错。

define(["dojo/_base/declare", "dojo/_base/lang", "dojo/_base/xhr",
     "dojo/_base/json", "dojo/_base/Deferred"], 
         function(declare,lang,xhr,json,Deferred) {

     return {
            mobGetLocationLatLng: function(pAddress) {          

                   console.log("+++adapter1.mobGetLocationLatLng+++pAddress" +
     pAddress );

         try{
            var invocationData = {
                    adapter : 'GeoCode',
                    procedure : 'getGmapLatLng',
                    parameters : [pAddress]
                    };

            console.log("+++about to invoke procedure+++"+ JSON.stringify(invocationData)); 
            WL.Client.invokeProcedure(invocationData,{
                onSuccess : this.gMapLatLngSuccess,
                onFailure : this.gMapLatLngFailure
            });
        }
        catch (e){
            console.log('Error...:' + e.message);
        }

    },
    gMapLatLngSuccess: function (result){
        console.log('Success:');
        console.log('<<<<<adapter1.result>>>>>>>>> ' + JSON.stringify(result.invocationResult));
        return result.invocationResult;
    },
    gMapLatLngFailure: function(){
        console.log('Failure');
    }
  };
});

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

测试1:证明适配器独立工作(无JavaScript)

尝试右键单击GeoCode适配器文件夹&gt;部署适配器&gt;调用程序&gt; ...

有用吗?你能回到你的期望吗?

测试2:证明适配器调用是隔离的(JavaScript)

尝试在现有Worklight项目(可访问GeoCode适配器)下创建新的Hybrid Worklight应用程序(wlapp)&gt;打开wlapp.js&gt;用以下代码替换里面的所有代码:

function wlCommonInit () {

    WL.Client.invokeProcedure({
        adapter : 'GeoCode',
        procedure : 'getGmapLatLng',
        parameters : ['hardcode_valid_value_here']
        },{
        onSuccess : function(res){ console.log('win', res); },
        onFailure : function(res){ console.log('fail', res); }
    });
}

注意: 'hardcode_valid_value_here'应替换为有效值。

尝试隔离问题,好像您只是从应用中复制/粘贴代码而不试图隔离错误。

有用吗?你能回到你的期望吗?

测试3:证明Worklight脚本标签没有问题

如果您使用多个HTML网页,take a look at this StackOverflow reply。如果您在一个HTML页面中包含所有内容,它是否有效?

测试4:尝试调试器

打开Goog​​le Chrome&gt;打开WL控制台(localhost:8080 / console)&gt;预览为公共资源&gt; WL.Client.invokeProcedure致电Add a Break Point&gt;确保代码执行并在断点处停止&gt;继续单步执行/遍历代码。分享导致问题的代码。

根据上述测试更多信息更新您的问题。

编写代码的其他方法

function wlCommonInit () {

//Define your LocationSingleton under myNameSpace
var myNameSpace = myNameSpace || {};
myNameSpace.LocationSingleton = (function ($) {

        //Private Members:
        var _getLocationFromAdapter = function (pAddress) {

            var deferred = $.Deferred(),

                    invocationData = {
                        adapter : 'GeoCode',
                        procedure : 'getGmapLatLng',
                        parameters : [pAddress]
                    },

                    success = function (res) {
                        console.log('Worked:', res);
                        deferred.resolve(res);
                    },

                    failure = function (err) {
                        console.log('Failed:', err);
                        deferred.reject(err);
                    };

                    console.log('Calling getLocationFromAdapter with:', invocationData);
                    WL.Client.invokeProcedure(invocationData, {
                        onSuccess : success,
                        onFailure : failure
                    });

                    return deferred.promise();
        };

        //Public API:
        return {
            getLocationFromAdapter : _getLocationFromAdapter
        };

}(WLJQ));


        //Usage: Calling the function and getting the location or a failure
        myNameSpace.LocationSingleton.getLocationFromAdapter('hardcode_valid_value_here')

        .then(function (res) {
            console.log('Done:', res);
        })

        .fail(function (err) {
            console.log('Err:', err);
        });

}
相关问题