Geometric representations of W-algebras and applications to the quantum Langlands correspondence