Realism or not, if somalian pirates in real life can fire rifles, submachine guns and rpgs from small rafts at huge oil tankers, im sure some ww2 u-boats did the same in dire need of some extra firepower.
Heck, if a musketman in the 1800's could shoot at another ship while standing high up on the mast while the ship bobs from side to side, i'm pretty sure a proper navy in ww2 could do the same, even when standing on a surfaced u-boat
Granted, your deck gun would be far more effective, but since when has the military or navy ever said no to a few extra guns, small or not?
It'd be an awesome mod idea, a few dudes with mp40's or rifles

Sure it would be useless versus a military vessel, but against a small lonely merchant that you dive up behind 50 meters away, it might be useful!