本文介绍了调用WL.Client.invokeProcedure时遇到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用工作灯适配器,并向外部服务打个电话.在执行工作灯方法 WL.Client.invokeProcedure(invocationData,options)时,调试区域出现以下错误:

I am invoking a worklight adapter and making restful call to external service. While executing worklight method WL.Client.invokeProcedure(invocationData,options) getting below error on debug area:

下面是我的适配器调用实现,不确定在哪里出错.

Below is my adapter call implementation not sure where I'm making mistake.

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:证明适配器能够独立运行(没有JavaScript)

尝试右键单击GeoCode适配器文件夹>部署适配器>调用过程> ...

Test 1: Prove the Adapter Works in isolation (no JavaScript)

Try right clicking the GeoCode adapter folder > Deploy Adapter > Invoke Procedure > ...

行得通吗?你能得到你想要的东西吗?

Does it work? Do you get back what you expect?

尝试在现有的Worklight项目(可以访问GeoCode适配器)下创建一个新的Hybrid Worklight应用程序(wlapp)>打开 wlapp.js >用以下内容替换其中的所有代码:

Try creating a new Hybrid Worklight Application (wlapp) under your existing Worklight Project (that has access to the GeoCode adapter) > Open wlapp.js > Replace all the code inside with the following:

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'替换为有效值.

Note: 'hardcode_valid_value_here' should be replaced with a valid value.

尝试隔离问题,似乎您只是从应用中复制/粘贴代码而未尝试隔离错误.

Try to isolate the issue, seems like you just copy/pasted code from your app without trying to isolate the error.

行得通吗?你能得到你想要的东西吗?

Does it work? Do you get back what you expect?

如果您使用多个HTML页面,请查看此StackOverflow答复.如果您将所有内容都放在一个HTML页面中,那么可以正常工作吗?

If you're using multiple HTML pages, take a look at this StackOverflow reply. If you have everything inside a single HTML page, does it work?

打开Goog​​le Chrome浏览器>打开WL控制台(localhost:8080/console)>以公共资源预览> WL.Client.invokeProcedure 调用中添加断点>确保代码已执行并在断点处停止>继续单步执行/遍历编码.共享导致问题的代码.

Open Google Chrome > Open the WL Console (localhost:8080/console) > Preview as Common Resources > Add a Break Point to the WL.Client.invokeProcedure call > Make sure that code gets executed and stops at the Break Point > Keep Stepping into / Traversing the code. Share the code that causes the issue.

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);
        });

}

这篇关于调用WL.Client.invokeProcedure时遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:31