1
我試圖使用node-soap訪問國家鐵路API。當試圖通過節點調用國家鐵路SOAP API時出現TypeError
文檔是在這裏:https://lite.realtime.nationalrail.co.uk/OpenLDBWS/
我是新來的SOAP所以這可能無法與API的問題。我正在用我的任何嘗試類型錯誤......
TypeError: Cannot read property 'Body' of undefined
這裏是我使用的嘗試撥打電話代碼:
var soap = require('soap');
var url = 'https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2014-02-20';
var soapHeader = '<com:AccessToken>MY_TOKEN</com:AccessToken>';
soap.createClient(url, function(err, client){
var args = {
numRows : 10,
crs : 'LAN'
};
client.addSoapHeader(soapHeader);
client.GetDepartureBoard(args, function(err, result){
if(err){
console.log('error!');
throw err;
}
console.log(result);
});
});
使用節點皁我還可以得到請求包絡,這是內容:
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://thalesgroup.com/RTTI/2014-02-20/ldb/"
xmlns:tok="http://thalesgroup.com/RTTI/2013-11-28/Token/types"
xmlns:ct="http://thalesgroup.com/RTTI/2007-10-10/ldb/commontypes"
xmlns:ldbt="http://thalesgroup.com/RTTI/2012-01-13/ldb/types"
xmlns:ldbt2="http://thalesgroup.com/RTTI/2014-02-20/ldb/types">
<soap:Header>
<com:AccessToken>MY_TOKEN</com:AccessToken>
</soap:Header>
<soap:Body>
<tns:GetDepartureBoardRequest
xmlns:tns="http://thalesgroup.com/RTTI/2014-02-20/ldb/"
xmlns="http://thalesgroup.com/RTTI/2014-02-20/ldb/">
<tns:numRows>10</tns:numRows>
<tns:crs>LAN</tns:crs>
</tns:GetDepartureBoardRequest>
</soap:Body>
</soap:Envelope>