We consider the calculation of electromagnetic fields generated by an electron bunch passing through a vacuum chamber structure that, in general, consists of an entry pipe, followed by some kind of transition or cavity, and ending in an exit pipe. We limit our study to structures having rectangular cross-section, where the height can vary as function of longitudinal coordinate but the width and side walls remain fixed. For such structures, we derive a Fourier representation of the wake potentials through one-dimensional functions. A new numerical approach for calculating the wakes in such structures is proposed and implemented in the computer code ECHO(2D). The computation resource requirements for this approach are moderate and comparable to those for finding the wakes in 2D rotationally symmetric structures. Numerical examples obtained with the new numerical code are presented.