worklight适配器调用Web服务。错误无法读取属性Body

时间:2013-03-15 09:20:54

标签: ibm-mobilefirst

调用以下适配器返回Ecma Error: TypeError: Cannot read property \"Body\" from undefined.

我已经读过类似的帖子了

-Dorg.xml.sax.driver = com.sun.org.apache.xerces.internal.parsers.SAXParser

到eclipse.ini 但没有解决问题。

function getStateDetails(idstate) { 
    var request='<?xml version="1.0" encoding="utf-8"?>'+
      '<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>'
      + '<test_demo><in0>{idstate}</in0></test_demo>'
      +'</soap:Body>'
      +'</soap:Envelope>';

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

    var result = WL.Server.invokeHttp(input);
    return result.Envelope.Body;
}

2 个答案:

答案 0 :(得分:1)

最后,在soapui的帮助下并在请求中添加标题可以正常工作。

function getStateDetails(idstate) {
var request='<?xml version="1.0" encoding="UTF-8"?>'
        +'<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">'
        +'<Body><test_demo xmlns="http://www.ibm.com/informix/i4gl-soa/2010-11/ws_commandes">'
        +'<in0>'+idstate+'</in0></test_demo>'
        +'</Body></Envelope>';

        WL.Logger.debug("SOAP Request " + request);
            var input = {
                method : 'post',
                returnedContentType : 'xml',
                headers: {SOAPAction: 'test_demo'},
                path : '/axis2/services/ws_commandes',
                body : {
                    content: request.toString(),                  
                    contentType: 'text/xml; charset=utf-8'                
                }               

            };
            var result = WL.Server.invokeHttp(input);               
            return result.Envelope.Body.test_demo_response;
}

答案 1 :(得分:0)

看起来你正在向WSDL发出请求,而不是服务本身。