I am calling a SOAP API that returns XML and am receiving the following error
Error -
title>401 - Unauthorized: Access is denied due to invalid credentials.</title>
I have used the information I can find on others SO queries, SOAP info and my specific calls documentation and this is my code that I have put together so far for it
String soap =
'''<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://thalesgroup.com/RTTI/2014-02-20/ldb/"
xmlns:ns2="http://thalesgroup.com/RTTI/2017-10-01/ldb/GetDepartureBoard">
<SOAP-ENV:Header>
<ns2:AccessToken>
<ns2:TokenValue>my_token</ns2:TokenValue>
</ns2:AccessToken>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetDepartureBoardRequest>
<ns1:numRows>10</ns1:numRows>
<ns1:crs>MAN</ns1:crs>
</ns1:GetDepartureBoardRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>''';
// Send the POST request, with full SOAP envelope as the request body.
http.Response response = await http.post(Uri.parse(
'https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx'),
headers: {
'Content-Type': 'text/xml; charset=utf-8',
'SOAPAction': 'http://thalesgroup.com/RTTI/2017-10-01/ldb/GetDepartureBoard'
},
body: soap
);
var rawXmlResponse = response.body;
final parsedXml = XmlDocument.parse (rawXmlResponse);
print(parsedXml);
}
The provider of the API states in their documentation
This token shall be passed as a SOAP Header value.
Is my inclusion in the body
enough or how do I reference it in the section...
headers: {
'Content-Type': 'text/xml; charset=utf-8',
'SOAPAction': 'http://thalesgroup.com/RTTI/2017-10-01/ldb/GetDepartureBoard'
Here is an example - https://wiki.openraildata.com/index.php/GetDepBoardWithDetails
Data from - https://realtime.nationalrail.co.uk/OpenLDBWS/
Thank you
Updated call
String soap =
'''
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://thalesgroup.com/RTTI/2017-10-01/ldb/"
xmlns:ns2="http://thalesgroup.com/RTTI/2013-11-28/Token/ns2es">
<SOAP-ENV:Header>
<ns2:AccessToken>
<ns2:TokenValue>my_token</ns2:TokenValue>
</ns2:AccessToken>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetDepartureBoardRequest>
<ns1:numRows>10</ns1:numRows>
<ns1:crs>MAN</ns1:crs>
</ns1:GetDepartureBoardRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>''';
// Send the POST request, with full SOAP envelope as the request body.
http.Response response = await http.post(Uri.parse(
'https://realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2017-10-01'),
headers: {
'SOAPAction': 'http://thalesgroup.com/RTTI/2017-10-01/ldb/GetDepartureBoard'
},
body: soap
);
Updated response
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://thalesgroup.com/RTTI/2017-10-01/ldb/" targetNamespace="http://thalesgroup.com/RTTI/2017-10-01/ldb/">
<wsdl:import namespace="http://thalesgroup.com/RTTI/2017-10-01/ldb/" location="rtti_2017-10-01_ldb.wsdl"/>
<wsdl:service name="ldb">
<wsdl:port name="LDBServiceSoap" binding="tns:LDBServiceSoap">
<soap:address location="https://realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx"/>
</wsdl:port>
<wsdl:port name="LDBServiceSoap12" binding="tns:LDBServiceSoap12">
<soap12:address location="https://realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Which is this webpage - https://realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2017-10-01