使用Google Apps脚本访问SOAP服务

时间:2013-08-12 13:09:34

标签: soap google-apps-script

我正在尝试使用Google Apps脚本来拨打SOAP服务电话,我一直在努力修补一些方法来获得响应;但是,我不断收到错误。我已经默认尝试发送存储在我的电子表格中的消息的精确副本,我知道这些消息通过其他服务工作...仍然没有运气。这是Apps脚本代码:

function getVesselSummaryXMLStringFromName() {
  var wsdl = SoapService.wsdl("http://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL");
  Logger.log(wsdl.getServiceNames());

  var uscgService = wsdl.getPSIXData();

  var sheet = SpreadsheetApp.getActiveSheet();

  //Get working SOAP message
  var envelope = sheet.getRange("D1:D1").getValues();

  Logger.log(envelope);

    var result = uscgService.getenvelope;
    Logger.log(result);
  }

我通过http://www.soapclient.com/soapclient发送的SOAP消息是:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://cgmix.uscg.mil" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><SOAP-ENV:Body><tns:getVesselSummaryXMLString xmlns:tns="http://cgmix.uscg.mil"><tns:VesselID></tns:VesselID><tns:VesselID></tns:VesselID><tns:VesselName>Atlantic Salvor</tns:VesselName><tns:VesselName></tns:VesselName><tns:CallSign></tns:CallSign><tns:CallSign></tns:CallSign><tns:VIN></tns:VIN><tns:VIN></tns:VIN><tns:HullNum></tns:HullNum><tns:HullNum></tns:HullNum><tns:Flag></tns:Flag><tns:Flag></tns:Flag><tns:Service></tns:Service><tns:Service></tns:Service><tns:BuildYear></tns:BuildYear><tns:BuildYear></tns:BuildYear></tns:getVesselSummaryXMLString></SOAP-ENV:Body></SOAP-ENV:Envelope>

1 个答案:

答案 0 :(得分:1)

以下代码返回一个答案,所以也许你可以提供帮助。

...
var url = 'http://cgmix.uscg.mil/xml/PSIXData.asmx?WSDL';
var wsdl = SoapService.wsdl(url);
var servicePSIXData = wsdl.getPSIXData();
var params = Xml.element('getVesselSummaryXMLString', [
    Xml.attribute('xmlns', 'http://cgmix.uscg.mil'),
    Xml.element('VesselID', ['']),
    Xml.element('VesselName', ['Atlantic Salvor']),
    Xml.element('CallSign', ['']),
    Xml.element('VIN', ['']),
    Xml.element('HullNum', ['']),
    Xml.element('Flag', ['']),
    Xml.element('Service', ['']),
    Xml.element('BuildYear', [''])
]);
var result = servicePSIXData.getVesselSummaryXMLString(params);
Logger.log(result.toXmlString());
...

<强>更新

Xml ServicesSoap Services都被视为deprecated