We derive an exact expression for the correlation function in redshift shells including all the relativistic contributions. This expression, which does not rely on the distant-observer or flat-sky approximation, is valid at all scales and includes both local relativistic corrections and integrated contributions, like gravitational lensing. We present two methods to calculate this correlation function, one which makes use of the angular power spectrum C_ell(z1,z2) and a second method which evades the costly calculations of the angular power spectra. The correlation function is then used to define the power spectrum as its Fourier transform. In this work theoretical aspects of this procedure are presented, together with quantitative examples. In particular, we show that gravitational lensing modifies the multipoles of the correlation function and of the power spectrum by a few percents at redshift z=1 and by up to 30% at z=2. We also point out that large-scale relativistic effects and wide-angle corrections generate contributions of the same order of magnitude and have consequently to be treated in conjunction. These corrections are particularly important at small redshift, z=0.1, where they can reach 10%. This means in particular that a flat-sky treatment of relativistic effects, using for example the power spectrum, is not consistent.