maybe you have to adapt some open-source routing solution which are listetd here, so that they can do a routing on railways?
http://wiki.openstreetmap.org/wiki/Routing