A dynamical model for the extra-planar gas in spiral galaxies