http://uboat.net/types/viic.htm by the U-Boat number, this boat should have been a Type VIIC. the movie version does look simular, but you have to remember, its a movie.
These type subs were issued with a deck gun, for surface use. the standard was a 88mm/45 caliber (see the explanation of gun caliber in the technology section). they carried 220 rounds for this weapon. Machine guns were various as to the whims of the captains.
Most submarine captains in the early part of the war preferred to conserve their torpedoes by surfacing on single ships, giving the crew of the ship time to abandon and then sinking it with the deck gun. Later on, when the ships were being armed to fight back, and blimps and patrol bomber air craft were increased...the U-Boat took it back under the sea, as it was too dangerous to go to surface action.
How does a weapon keep dry? it doesn't. theres no way to make a breech or a plug that can resist pressure. the guns were made from saltwater resistant materials. A tampion plug was placed in the muzzle end to prevent weird sea creatures from finding a home in the barrel. To fire the weapon, you elevated the muzzle, pouring the water from the open breach after removing the tampion, and then sighting thru the open breech to ensure you would not shoot anything foreign in the barrel.