Statistical field theory with constraints: Application to critical Casimir forces in the canonical ensemble.