Note: This article is for customers interested in creating their own web service. Trimble MAPS also hosts and maintains a PC*MILER Rail web service. It is available on a subscription basis.


If you are planning to call PC*MILER Rail from a web service, below you will find sample code along with the imports for PC*MILER Rail Connect APIs. The example code demonstrates how to open and close the server and has a call to look up mileage. This will allow you to create a sample .NET client with PC*MILER Rail Connect APIs for .NET use. Please follow the dllImport convention below for defining any other functions from PC*MILER Rail API set.


For the data type mapping, the rules are:

  • Use int or integer for longs and shorts. The TRIPID should be declared as Int or Integer.
  • Use StringBuilder for returned strings.
  • Use ref or ByRef for long/int/short pointers to returned pointers.


The following PC*MILER Rail functions declared below were tested with PC*MILER Rail Version 18. Note that there is a potential for a declaration error in the future due to differences in Win 32 declarations of "C" functions in our unmanaged DLLs. Therefore, the dllimports may need to be changed with future versions of PC*MILER Rail.


using System;
using System.Text;
using System.Runtime.InteropServices;

namespace RailServer
{
public abstract class DemoServer
  {
  [DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSInitSrv")]
  public static extern Int32 InitSrv(String callerName, String iniFile);

  [DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSCleanupSrv")]
  public static extern Int32 CleanupSrv();

  [DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSNewTrip")]
  public static extern Int32 PCRSNewTrip(ref Int32 tripId);

  [DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSDeleteTrip")]
  public static extern Int32 PCRSDeleteTrip(Int32 tripId);

  [DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSSetRouteFormula")]
  public static extern Int32 PCRSSetRouteFormula(Int32 tripId, String newParam);

  [DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSSetRouteMethod")]
  public static extern Int32 PCRSSetRouteMethod(Int32 tripId, String newParam);

  [DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSSetRouteType")]
  public static extern Int32 PCRSSetRouteType(Int32 tripId, String newParam);

  DllImport("C:\\Windows\\pcrsrv32.dll", EntryPoint = "PCRSCalcTrip")]
  public static extern Int32 PCRSCalcTrip(Int32 tripId, String orig, String origRR, String origGeo,
    String dest, String destRR, String destGeo, ref Int32 miles);
  }

class Program
{
  static void HandleError(Int32 errCode)

  Console.WriteLine("error code: " + errCode + "\n\nPress any key to finish...");
  Console.ReadLine();
  Environment.Exit(errCode);
  }

     static void Main(string[] args)
     {
  Int32 srvRet = -1;
  Int32 myTrip = 0;


Step 1: Initialize the Server

if (0 != (srvRet = DemoServer.InitSrv("Rail Server Test", "C:\\WINDOWS\\pcrsrv.ini")))
  {
  Console.WriteLine("Server failed to start...");
        HandleError(srvRet);
  }
  else
  Console.WriteLine("Server started...\n");


Step 2: Request a New Trip Handle from the Server

if (0 != (srvRet = DemoServer.PCRSNewTrip(ref myTrip)))
  Environment.Exit(srvRet);


Step 3: Set the Routing Options (The following options are the defaults)

srvRet = DemoServer.PCRSSetRouteFormula (myTrip, "P");  /* Practical */
  srvRet = DemoServer.PCRSSetRouteMethod (myTrip, "F");  /* Familized */
  srvRet = DemoServer.PCRSSetRouteType (myTrip, "I");  /* Interactive */


Step 4: Compute Denver to Oakland route on UP (single carrier)

Int32 miles_tenths = 0;
  Single miles;
  if (0 != (srvRet = DemoServer.PCRSCalcTrip(myTrip, "DENVER CO", "UP", "C",
  "OAKLAND CA", "UP", "C", ref miles_tenths)))
  {
  Console.WriteLine("PCRSCalcTrip() error...");
    HandleError(srvRet);
  }
  else
  {
    miles = (Single) miles_tenths / 10;
    Console.WriteLine ("Denver CO (on UP) to Oakland CA (on UP) is " + miles + " miles.\n");
  }


Step 5: Trip Cleanup - Release Mem for Trip

if (0 != (srvRet = DemoServer.PCRSDeleteTrip (myTrip)))
  {
  Console.WriteLine("PCRSDeleteTrip() error...");
  HandleError(srvRet);
  }


Step 6: Clean Up Server

if (0 != (srvRet = DemoServer.CleanupSrv()))
  {
  Console.WriteLine("Server failed to stop...");
    HandleError(srvRet);
  }
  else
  Console.WriteLine("Server stopped...\n");

     Console.WriteLine("Press any key to finish... ");
     Console.ReadLine();
     }
  }
}