我在使用wsdl soap请求中的多个元素时遇到问题。当我直接在webservicex网站上尝试以下转换时,我获得当前的货币转换。当我尝试在app脚本中执行相同的操作时,它总是返回“0”的速率。我在这里缺少什么?
function getCurrencyConversion2(){
var fromCurr = "USD";
var toCurr = "AUD";
var wsdl = SoapService.wsdl("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL");
Logger.log(wsdl.getServiceNames());
var currencyService = wsdl.getService("CurrencyConvertor");
Logger.log(currencyService.getOperationNames());
//var convertOp = currencyService.getOperation("ConversionRate");
var param = Xml.element("ConversionRate", [
Xml.attribute("xmlns", "http://www.webservicex.net/"),
Xml.element("FromCurrency", [fromCurr]),
Xml.element("ToCurrency", [toCurr])
]);
var result = currencyService.invokeOperation("ConversionRate", [param]);
return;
}
答案 0 :(得分:5)
你会喜欢这个。我也困扰了一段时间。
问题是xmlns
的属性区分大小写。当正确的版本为http://www.webservicex.net/
时,您将其添加为http://www.webserviceX.NET/
。请注意最后的X.NET
。
以下调整版本应该可以正常工作(以0.9602作为汇率记录XML)。
function getCurrencyConversion2(){
var fromCurr = "USD";
var toCurr = "AUD";
var wsdl = SoapService.wsdl("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL");
var currencyService = wsdl.getService("CurrencyConvertor");
var param = Xml.element("ConversionRate", [
Xml.attribute("xmlns", "http://www.webserviceX.NET/"),
Xml.element("FromCurrency", [fromCurr]),
Xml.element("ToCurrency", [toCurr])
]);
var result = currencyService.invokeOperation("ConversionRate", [param]);
Logger.log(result.toXmlString());
return;
}
由于SOAP的复杂性以及此服务未返回有价值的错误消息,这很痛苦。