5

I've registered for a token to access the National Rail (UK), Live Departure Boards API, but I can't seem to get it to work. Can anybody point out what I'm doing wrong?

I used WSDL.EXE to build a C# SOAP Proxy class, as specified here: https://realtime.nationalrail.co.uk/ldbws/

The generated .cs proxy file is 1318 lines long, but it looks correct.

My code is as follows: (LDBServiceSoap is the generated proxy class)

static void Main(string[] args)
{
    LDBServiceSoap ldb = new LDBServiceSoap();

    ldb.AccessTokenValue = new AccessToken() {
        TokenValue = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    };

    StationBoard sb = ldb.GetDepartureBoard(4, "WAT", "VIC", FilterType.from, 0, 120);
}

The Url is set inside the proxy class, so I can't think of anything else I need to do.

But when the debugger gets up to the GetDepartureBoard method, it throws a WebException "The request failed with HTTP status 401: Unauthorized."

Does anybody know what I'm missing / doing wrong here?

You're awesome!

juharr
  • 31,741
  • 4
  • 58
  • 93
Graeme Job
  • 51
  • 2

3 Answers3

1

If you obtained your access token through the OpenLDWS signup then your token will only work on the https://realtime.nationalrail.co.uk/OpenLDBWS/ endpoint that could be your problem

George McDonnell
  • 1,445
  • 1
  • 16
  • 21
1

Not sure how you've generated your sources but I've managed to get a working version using this Web service client given WSDL to generate the sources from the WSDL:

wsimport -extension -keep -XadditionalHeaders https://lite.realtime.nationalrail.co.uk/OpenLDBWS/wsdl.aspx?ver=2016-02-16

Then I call the method once the sources are on the classpath with the following:

AccessToken token = new AccessToken(); // This class is generated from the WSDL
token.setTokenValue("yourTokenHere");

Ldb ldb = new Ldb();

LDBServiceSoap api = ldb.getLDBServiceSoap();

GetBoardRequestParams reqParams = new GetBoardRequestParams();
reqParams.setCrs("STA"); // Station Code
reqParams.setNumRows(10);
reqParams.setTimeOffset(-120);

StationBoardResponseType departures = api.getDepartureBoard(reqParams, token);
Rob Evans
  • 2,822
  • 1
  • 9
  • 15
0

Though the answer from Rob Evans did not completely provide the solution, it did show me the right direction. I had to implement this in C# and below code worked for me.

        AccessToken token = new AccessToken();
        token.TokenValue = "xxx-xxx-xxx";
        ldb client = new ldb();
        client.AccessTokenValue = token;
        StationBoard sb = client.GetDepartureBoard(10, "ABW", "", FilterType.to, 0, 120);
bikram s.
  • 327
  • 5
  • 16