Current "chemical rifles" use shock absorbers (springs and padded buttplates on the shoulder stocks) plus extra mass to counteract the recoil. Electromagnets might be able to counter the recoil from a railgun.
(Note that I question the value of enormously powerful "railrifles". Since infantry combat is fought at close range, soldier don't need enormously powerful shoulder weapons. 7.9262 NATO is more than powerful enough. What they need is lots of ammo, which is why sub-machine guns and intermediate cartridges like 7.9x3962x39 & 5.56 NATO were developed.)