Short version: EM pulse weapons are nowhere near as small and convenient as they look in the movies, and they are also much easier to protect against than the movies would have you believe. Military hardware is protected, and even a lot of civilian hardware has a reasonable level of protection, as small EM pulses are a fact of everyday life (coming from lightning, faulty lightswitches, cheap DC motors and many other things).
First, what is an EM pulse, and why is it a problem? It is a pulse of electromagnetic radiation, usually spread out over a very wide range of frequencies, but lasting a short time. It will cause currents to flow in metal objects it reaches, and if those metal objects are part of an electronic circuit the unexpected current will damage the circuit.
Second, how can one protect against it? A sheet of metal will block most of the electromagnetic pulse. It will travel through small holes and round corners though. Military vehicles and ships tend to be made of metal, and tend to not have many holes which might let blast waves or toxic gas in, so they are pretty good shielding anyway.
The second way to protect against an EM pulse is to harden the actual electronics by providing somewhere for the big current pulse caused by the EMP to go where it won't do any damage. For example, you can build in special diodes to short out the unwanted current.
Neither of these methods is perfect. With a strong enough EMP, the pulse will overwhelm the protective elements on the circuit board, and the metal sheets only reduce the pulse, not block it entirely.
Third, is it practical to build an EMP weapon? You can produce a pulse with something which works a lot like a big radio. You can produce a bigger pulse by connecting a powerful electromagnet to an antenna, then crushing the magnet flat with explosives. But neither produces that big of a pulse, and because the pulse spreads out very quickly the range is miserable.
The second way to make an EM pulse is to detonate a nuke. Preferably a specially adapted nuke, but any nuke will do if it is detonated in the right part of the atmosphere. The hardening on military equipment, is really designed to deal with this, so they can keep fighting after a nuke near miss, but it has the side effect of making non-nuclear EMPs pretty pointless.
Finally, is a railgun more susceptible to damage than e.g. a modernised 16" gun? Both probably have similar fire control systems, which will be equally vulnerable. The railgun has an electric system for accelerating the projectile, but that system is designed to operate with truly enormous currents, so the currents induced by an EMP won't do any damage.
As for examples of EMP use - I have never come across any examples of non-nuclear EMP devices having any real effect except at blank point range. At which point a regular bomb would be much more destructive. Nuclear EMPs are another story however, successful tests have been made, and in one case (starfish prime) they accidentally caused significant damage to satellites ins orbit and electrical installations in Hawaii.