2012-08-05 98 views
0

我試圖從谷歌應用程序腳本訪問Numara Footprints Web服務API。 Web服務沒有wsdl,但是這些方法都有很好的文檔記錄。所有使用Google Apps腳本Soap服務的示例都假定存在wsdl文件,這使得它對我而言不起作用。所以我想改用UrlFetchApp。通過使用示例PHP代碼ヌ足跡提供,我建立請求應該是什麼樣子,並寫在谷歌下面的代碼Google Apps腳本:谷歌應用程序腳本肥皂客戶端沒有wsdl

function sendHttpPost() { 
var payload= '<?xml version="1.0" encoding="utf-8"?>' + 
'<SOAP-ENV:Envelope'+ 
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'+ 
'xmlns:ns1="MRWebServices"'+ 
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' + 
    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' + 
    'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"' + 
     'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+ 
     '<SOAP-ENV:Body>'+ 
     '<ns1:MRWebServices__search>'+ 
     '<param0 xsi:type="xsd:string">ACCOUNT NAME</param0>'+ 
     '<param1 xsi:type="xsd:string">PASSWORD</param1>'+ 
     '<param2 xsi:type="xsd:string"></param2>'+ 
      '<param3 xsi:type="xsd:string">'+ 
"SELECT * from MASTER1 where mrid='16888'</param3>"+ 
      '</ns1:MRWebServices__search>'+ 
      '</SOAP-ENV:Body>'+ 
      '</SOAP-ENV:Envelope>'; 



var headers = 
    { 
    "SOAPAction" :encodeURIComponent("MRWebServices#MRWebServices__search") 
      }; 

var options = 
{ 
    "contentType": "text/xml; charset=utf-8", 
    "method" : "post", 
    "headers" : headers, 
    "payload" : payload 
}; 
UrlFetchApp.fetch("http://FOOTPRINTS SERVER/MRcgi/MRWebServices.pl", options); 
} 

此代碼與服務器聯繫成功,並得到返回以下錯誤消息:

Request failed for http://FOOTPRINTS SERVER/MRcgi/MRWebServices.pl 
returned code 500. Server response: 
<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/1999/XMLSchema" 
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Body> 
<SOAP-ENV:Fault> 
<faultcode>SOAP-ENV:Client</faultcode> 
<faultstring>Application failed during request deserialization: 
not well-formed (invalid token) at line 1, column 70, byte 70 at 
C:/FootPrints/bin/Perl/lib/XML/Parser.pm line 187 </faultstring> 
</SOAP-ENV:Fault> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> (line 40) 

我不知道有什麼辦法可以得到更詳細的錯誤信息,我不知道問題出在哪裏。我發送的XML直接從完美工作的PHP代碼中複製。

我想知道,如果有人或者:

  1. 可以看到一個問題與谷歌Apps腳本代碼的上方或
  2. 能告訴我如何使用谷歌Apps腳本SOAP服務的時候我不知道有一個wsdl文件或
  3. 知道一種獲取Web服務的方式來返回更多的錯誤細節。

在此先感謝。我到處都能看到我能想到的東西,但沒有找到答案。

回答

0

上述代碼中的有效載荷var需要XML元素之間的空格。修正碼(在每一行的末尾註空格):

var payload= '<?xml version="1.0" encoding="utf-8"?> ' + 
'<SOAP-ENV:Envelope '+ 
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '+ 
'xmlns:ns1="MRWebServices" '+ 
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' + 
    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + 
    'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" ' + 
     'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> '+ 
     '<SOAP-ENV:Body> '+ 
     '<ns1:MRWebServices__search> '+ 
     '<param0 xsi:type="xsd:string">ACCOUNT NAME</param0> '+ 
     '<param1 xsi:type="xsd:string">PASSWORD</param1> '+ 
     '<param2 xsi:type="xsd:string"></param2> '+ 
      '<param3 xsi:type="xsd:string"> '+ 
      "SELECT * from MASTER22 where mrid='16888'</param3> "+ 
      '</ns1:MRWebServices__search> '+ 
      '</SOAP-ENV:Body> '+ 
      '</SOAP-ENV:Envelope>'; 

此外,在頭,我並不需要使用encodeURIComponent方法()。更正後的編碼:

var headers = 
    { 
    "SOAPAction" :"MRWebServices#MRWebServices__search" 
      };