In 1956, Tong established an asymptotic formula for the mean square of the error term in the summatory function of the Piltz divisor function $d_3(n).$ The aim of this paper is to generalize Tongs method to a class of Dirichlet series that satisfy a functional equation. As an application, we can establish the asymptotic formulas for the mean square of the error terms for a class of functions in the well-known Selberg class. The Tong-type identity and formula established in this paper can be viewed as an analogue of the well-known Voronois formula.