2014-01-16 2 views
0

Я собираюсь разработать скрипт приложения Google для чтения данных из электронной таблицы google и передачи данных в мыльный веб-сервис.передать данные электронной таблицы google на веб-службу мыла

Вот сценарий,

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

какой тип веб-сервиса SOAP или REST? - обновите вопрос –

+0

Это веб-сервис SOAP –

ответ

0

Для начала вам нужно будет построить мыло ввода XML, как определено в WSDL т.е. параметры должны быть преобразованы к 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); 

    } 
Смежные вопросы