我将开发一个谷歌应用程序脚本,以从谷歌电子表格中读取数据,并将数据传递给肥皂网络服务。
这是脚本,
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Get the range of cells that store employee data.
var studentDataRange = ss.getActiveRange();
// For every row of student data, generate an student object.
var studentObjects = getRowsData(sheet, studentDataRange);
for (var i=0; i<studentObjects.length; i++)
{
var student = studentObjects[i];
var options = {
"studentId" : student.studentId,
"Marks" : student.marks,
"url" : ss.getUrl(),
} ;
//Here i want to pass the options values to a web service.
}
任何人都可以帮我解决这个问题。
由于
答案 0 :(得分:1)
首先,您需要构建WSDL定义的soap输入XML,即必须将选项转换为定义格式的XML,然后需要使用URL Fetch来调用SOAP WS。获得汇率的样本
function WS_Currency() {
var soapIn = XmlService.parse(
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/soap/envelope/"></soap12:Envelope>'); // We cannot build the XML from scratch as GAS XML does not allow multiple NS for root
var soapEnv = soapIn.getRootElement();
//Build your soap message
var soapNS = soapEnv.getNamespace("soap12");
var apiNS = XmlService.getNamespace("http://www.webserviceX.NET/");
var soapBody = XmlService.createElement("Body", soapNS);
var ConversionRate = XmlService.createElement("ConversionRate", apiNS);
var FromCurrency = XmlService.createElement("FromCurrency", apiNS).setText('USD');
var ToCurrency = XmlService.createElement("ToCurrency", apiNS).setText('GBP');
ConversionRate.addContent(FromCurrency);
ConversionRate.addContent(ToCurrency);
soapBody.addContent(ConversionRate);
soapEnv.addContent(soapBody);
// Set the http options here
var options =
{
"method" : "post",
"contentType" : "text/xml; charset=utf-8",
"payload" : XmlService.getRawFormat().format(soapIn),
"muteHttpExceptions" : true
};
// Call the WS
var soapCall= UrlFetchApp.fetch("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL", options);
// Extract the output, yeah this is the only way we need to traverse the received XML :(
var cRate = XmlService.parse(soapCall.getContentText()).getRootElement().getChild("Body", soapNS).getChild("ConversionRateResponse", apiNS).getChild("ConversionRateResult", apiNS).getValue();
Logger.log(cRate);
}