Then the answer is simple: Have a zero tolerance for such activity in the military. If you attempt to engage in any homosexual activity in the course of military service, you're out. The question, howoever, seems to be whether it's necessary to bar anyone who itentifies himsef as homosexual as a prerequisite. There's a difference between being gay and engaging in gay bahavior. Certainly, most men in the military are heterosexual, but do not engage in heterosexual acts while in service. It would not be unreasonable, therefore, to expect of a gay man who enlists to refrain from gay activity during his service.
Zero tolerance is the right attitude! But a person who professes to be a homosexual should be excluded from the beginning! Why should we wait until it is manifested by an act of homosexuality when the person states their intention in advance? By the same common sense we routinely disqualify people in many venues for varies reasons based upon their answers to relevant questions. It's pampering to provide exceptions for homosexuals.