Access via PTV .NET client access classes

  • While xServer internet uses HTTP basic authentication with <user>/<password>, it is highly recommended to work with the token assigned to your subscription using the combination “xtok”/<token>. Using the token is a safer way than using your far more sensible account data.

  • PTV provides pre-generated .NET assemblies which contain the classes to access xServer internet. For this tutorial you are going to need the xRoute .NET client package, the xserverbase .NET client and also the ICSharpCode.SharpZipLib which you can find in the "thirdparty" folder. Enter "xtok" as user and your token as password to access the download.

    Download xRoute client package

    Unzip the downloaded packages. In your Visual Studio project select "Add Reference" and browse to the wanted .dll-files.

  • The following code sample describes how to access the xRoute server, calculates a route and shows the result on the console. Pay attention to the green comments in the code.

//Don't forget the relevant using directives!
using ICSharpCode.SharpZipLib;
using com.ptvag.xserver.xroute.wsclient;
using com.ptvag.xserver.common.wsclient;
using com.ptvag.jabba.clientbase.wsclient;


namespace BasicAccessWithXRoute
{

    class Program
    {

        public static void Run()
        {
            //Initialize the client class with Username, Password and ServerUrl
            CXRouteClient client = new CXRouteClient(
                "xtok",
                "<insert your token here!>",
                "https://xroute-eu-n-test.cloud.ptvgroup.com/xroute/ws/XRoute"
            );


            // Initialize the Caller Context. Use Lon/Lat coordinates instead of the default PTV_Mercator
            client.CallerContext = new CallerContext { properties = new[] {
                       new CallerContextProperty { key = "CoordFormat", value = "OG_GEODECIMAL" }
             } };


            //Invoke the route calculation
            var xRouteResult = client.CalculateRoute(new[]{
                    new CWaypointDesc{Coords = new []{new CPoint{Point = new CPlainPoint{X = 7.10, Y = 50.73}}}},
                    new CWaypointDesc{Coords = new []{new CPoint{Point = new CPlainPoint{X = 10.00, Y = 53.55}}}}
            },
           null, null, new CResultListOptions()
           );

            // Display the result. In this case only the distance of the route is shown.
            System.Console.WriteLine("Distance: " + xRouteResult.Info.Distance);
            System.Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Run();

        }
    }
}
  • The output of this code sample should now look like this: