Skip to content

Instantly share code, notes, and snippets.

@jpsingleton
Created November 18, 2015 23:10
Show Gist options
  • Save jpsingleton/166c13a104bb0fa79f00 to your computer and use it in GitHub Desktop.
Save jpsingleton/166c13a104bb0fa79f00 to your computer and use it in GitHub Desktop.
National Rail UK Journey Planner SOAP API Example
using System;
using System.ServiceModel;
using OJP.RTJP; // service reference namespace
namespace OJP {
class Program {
static void Main() {
var binding = new BasicHttpsBinding {
Security = new BasicHttpsSecurity {
Mode = BasicHttpsSecurityMode.Transport,
Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.Basic }
}
};
var endpoint = new EndpointAddress("https://ojp.nationalrail.co.uk/webservices");
// Add a service reference to https://ojp.nationalrail.co.uk/webservices/jpdlr.wsdl
var client = new jpdlrClient(binding, endpoint);
if (client.ClientCredentials != null) {
client.ClientCredentials.UserName.UserName = "PUT USERNAME HERE";
client.ClientCredentials.UserName.Password = "PUT PASSWORD HERE";
}
client.Open();
// CRS codes at https://huxley.apphb.com/crs/ (for all) or search e.g. https://huxley.apphb.com/crs/kings%20cross
var request = new RealtimeJourneyPlanRequest {
origin = new CrsCode { Item = "KGX", ItemElementName = ItemChoiceType.stationCRS },
destination = new CrsCode { Item = "YRK", ItemElementName = ItemChoiceType.stationCRS },
outwardTime = new RealtimeJourneyPlanRequestOutwardTime { Item = DateTime.Now, ItemElementName = ItemChoiceType1.departBy }
};
var ojpResponse = client.RealtimeJourneyPlan(request);
Console.WriteLine("************** Journey Planning **************");
Console.WriteLine();
foreach (var journey in ojpResponse.outwardJourney) {
Console.WriteLine(journey.origin + " " + journey.timetable.scheduled.departure);
Console.WriteLine("**********************************************");
Console.WriteLine();
}
// East Coast, Great Western and South West
var cycleResponse = client.TOCCyclePolicy(new[] { "GR", "GW", "SW" });
Console.WriteLine("******************* Cycles *******************");
Console.WriteLine();
foreach (var tocCyclePolicy in cycleResponse) {
Console.WriteLine(tocCyclePolicy.policyDescription);
Console.WriteLine("**********************************************");
Console.WriteLine();
}
client.Close();
Console.WriteLine("Press any key to exit..."); // which key is the any key?
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment