有人请解释为什么它不起作用?
//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 回答
这是实现SOAP通信的旧方法,ti-soap是最好的,从Node.js SOAP移植到Titanium .
此外,如果您使用Alloy集合,您可以使用我的Alloy SOAP Adapter,它将使处理连接更容易,自动绑定到视图 .