首页 文章

SOAP调用不适用于Titanium

提问于
浏览
0

有人请解释为什么它不起作用?

//Create our application namespace
var my = {
suds : require('suds2'),
isAndroid : (Ti.Platform.osname === 'android'),
config : {
    endpoint:"http://www.webservicex.net/whois.asmx",
    targetNamespace: 'http://www.webserviceX.NET/',
    includeNS : true, 
    ns: 'ns0', 
    addTargetSchema : false                         
}   
};


// Create a simple window to show our results
(function(){

var win = Ti.UI.createWindow({
    backgroundColor:'#fff', layout:'vertical'
});

win.add(Ti.UI.createLabel({
    text:"SOAP Service", color:'#000', top:5, height:22, font:{fontWeight:'bold',fontSize:16} 
}));
win.add(Ti.UI.createLabel({
    text:"Press Go to see result", color:'#000', top:5, height:22, font:{fontSize:14} 
}));    

var label = Ti.UI.createLabel({
    top: 10, left: 10,
    width: 'auto', height: 'auto',
    text: 'Press go to start'
});
win.add(label);

var goButton = Ti.UI.createButton({
    title:'Go', left:10, top:10
});
win.add(goButton);

goButton.addEventListener('click',function(e){

    label.text ="Loading...";

    try {

        var sudsClient = new my.suds(my.config);

        sudsClient.invoke('GetWhoIS', 
            {
                HostName : 'www.google.com'
            }, 
            function(xmlDoc) {
                var results = xmlDoc.documentElement.getElementsByTagName('GetWhoISResponse');
                if (results.length>0) {
                    label.text = results.item(0).text;
                } else {
                    label.text = 'Oops, could not determine result of SOAP call.';
                }
            });

    } catch(e) {
        Ti.API.error('Error: ' + e);
    }       
});

win.open(); 

})();

注意:它适用于此服务:http://www.webservicex.net/CurrencyConvertor.asmx调用函数:ConversionRate

参数:FromCurrency:'EUR',ToCurrency:'USD'

回调函数:ConversionRateResult

2 回答

  • 0

    这是实现SOAP通信的旧方法,ti-soap是最好的,从Node.js SOAP移植到Titanium .

    此外,如果您使用Alloy集合,您可以使用我的Alloy SOAP Adapter,它将使处理连接更容易,自动绑定到视图 .

  • 0
    var soapRequest = "XML XML XML"; //write your xml request including the   parameters
    
    var client = Ti.Network.createHTTPClient();
    
    client.onerror = function(e) {Ti.API.info(e);};
    
    client.onload = function(e){var doc = this.responseXML.documentElement;}; //the response, you'll have to manually parse the xml
    
    client.open('POST', 'url'); //endpoint
    
    client.setRequestHeader("SOAPAction", "method"); //method of the web service.
    
    client.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    
    client.send(soapRequest); //send the xml
    

相关问题