A reciprocity theorem for ergodic actions