MobileFirst V8.0.0,cordova客户端应用程序无法从JavaScriptSOAP(SOAP集成)

时间:2017-03-07 06:58:09

标签: javascript ibm-mobilefirst mobilefirst-adapters mobilefirst-server

MobileFirst V8.0.0,cordova客户端应用程序无法从JavaScriptSOAP(SOAP集成)获得响应:

我在从Cordova客户端应用程序访问JavaScriptSOAP(示例适配器)时遇到问题,适配器JavaScriptSOAP没有响应。
我正在使用Mobilefirst Server 8.0 Development Foundation套件。

问题: 我不能得到回应的原因是什么呢 需要再次设置安全性,如果安全性在哪里设置它。

1)Client App Cordova(index.js)

var app = {
    // Application Constructor
    initialize: function() {
      this.bindEvents();
    },
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.getElementById("btn_submit").addEventListener('click', app.submitRequest);
    },

    submitRequest:function() {
var resourceRequest = new WLResourceRequest("/adapters/JavaScriptSOAP/getWeatherInfo", WLResourceRequest.GET);
resourceRequest.setQueryParameter("params", "['Washington', 'United States']");
 resourceRequest.send().then(app.onSuccess, app.onFailure);

    },
onSuccess: function(response) {
        WL.Logger.info("Success: " + response.responseText);
        window.plugins.spinnerDialog.hide();


       var $result = $(response.invocationResult.Envelope.Body.GetWeatherResponse.GetWeatherResult);
       var weatherInfo = {
        location: $result.find('Location').text(),
        time: $result.find('Time').text(),
        wind: $result.find('Wind').text(),
        temperature: $result.find('Temperature').text(),
    };

  document.getElementById("div_result").innerHTML= weatherInfo;
    },

    onFailure: function(response) {

        WL.Logger.info("Failure: " + JSON.stringify(response));
        window.plugins.spinnerDialog.hide();

        var resultText = "Failure: " + JSON.stringify(response);

        document.getElementById("div_result").innerHTML = resultText;
    }

};

2)Java Script Adapter - JavaScriptSOAP(来自GITHUB示例)

2.1)JavascriptSOAP-impl.js

function getWeatherInfo(cityName, countryName) {
    var request =
        <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
                <GetWeather xmlns="http://www.webserviceX.NET">
                    <CityName>{cityName}</CityName>
                    <CountryName>{countryName}</CountryName>
                </GetWeather>
            </soap:Body>
        </soap:Envelope>;

    var input = {
        method: 'post',
        returnedContentType: 'xml',
        path: '/globalweather.asmx',
        body: {
            content: request.toString(),
            contentType: 'text/xml; charset=utf-8'
        }
    };

    var result = MFP.Server.invokeHttp(input);

    var xmlDoc = new XML(result.Envelope.Body.GetWeatherResponse.GetWeatherResult);

    var weatherInfo = {
        Location: xmlDoc.Location.toString(),
        Time: xmlDoc.Time.toString(),
        Wind: xmlDoc.Wind.toString(),
        Temperature: xmlDoc.Temperature.toString()
    };

    MFP.Logger.debug("This is a debug message from a JavaScript adapter" + weatherInfo.Temperature);


    // return result.Envelope.Body;
    return weatherInfo;
};

2.2)adapter.xml

<mfp:adapter name="JavaScriptSOAP"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mfp="http://www.ibm.com/mfp/integration"
    xmlns:http="http://www.ibm.com/mfp/integration/http">

    <displayName>JavaScriptSOAP</displayName>
    <description>JavaScriptSOAP</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>www.webservicex.net</domain>
            <port>80</port>
        </connectionPolicy>
    </connectivity>

    <procedure name="getCitiesByCountry"/>
    <procedure name="getWeatherInfo"/>
</mfp:adapter>

1 个答案:

答案 0 :(得分:1)

您是否收到错误(如果有的话,请提及)?你得到了哪些响应代码

部署适配器后,我假设您收到了响应代码: 200

但未在&#34; GetWhetherResult&#34;。

中找到数据

您正在响应主体

   {
      "isSuccessful": true,
      "GetWeatherResponse": {
        "xmlns": "http://www.webserviceX.NET",
        "GetWeatherResult": "Data Not Found"
      }
    }

检入MobileFirst Swagger enter image description here

使用参数
MobileFirst Swagger