WASHINGTON — Corey Foster spent her Army career caring for wounded troops, both as a flight medic in the Iraq war and at Walter Reed hospital, so she looked forward to one of the most celebrated benefits of military service — health care for life from the Department of Veterans Affairs. Then she walked through the door at a V.A. medical center in Temple, Tex.

“You felt like you were a piece of meat,” said Ms. Foster, 34, who retired as a sergeant. “Standing in line at the registration desk, I was getting comments from the male patients behind me, looking me up and down. It was a major source of discomfort.”

The treatment was the same at the Veterans Affairs medical center in Murfreesboro, Tenn., where Ms. Foster moved after living in Texas. At that point she gave up, and opted for her husband’s insurance outside the department. “They need to make the facilities not feel like an old soldier’s home,” Ms. Foster said.

[Sign up for the weekly At War newsletter to receive stories about duty, conflict and consequence.]

An entrenched, sexist culture at many veterans hospitals is driving away female veterans and lags far behind the gains women have made in the military in recent years, veterans and lawmakers of both parties say. Although the Department of Veterans Affairs has scrambled to adjust to the rising population of female veterans and has made progress — including hiring more women’s health care providers, fixing basic privacy problems in the exam rooms and expanding service to women in rural areas — sexual harassment at department facilities remains a major problem.