Generally they were a large artillery piece, often surplus naval artillery, mounted on, transported by, and fired from a specially designed railway wagon. Many countries have built railway guns, but the best known are the large Krupp-built pieces used by Germany in WWII and WWI.
The largest artillery piece of this type deployed by Germany in WW2 was 80 cm Schwerer Gustav. Below an original image with Nazi gerarchs.
The effect to merge a railway locomotive and a siege mortar can be this
I took some pictures in a Italian scenario prepared by Ezio and Flavio. The idea is a short break for a military convoy that has to be refuelled
Unfortunately for railway gun the rise of the plane effectively ended their usefulness. Similar to battleships, they were massive, expensive, and, in the correct conditions, easily destroyed from the air