Fine mesh netting? After the flowers have been pollinated, cover the vines against the flies so that they can't lay their eggs on the developing fruit. I would assume that they wait until it's close to ripe and it's the smell that attracts them.
Here in the US fruit flies are an indoor species. Can you give us the genus and family name?
Here they are: "Drosophila (/drəˈsɒfɪlə, drɒ-, droʊ-/) is a genus of flies, belonging to the family Drosophilidae, whose members are often called "small fruit flies" or (less frequently) pomace flies, vinegar flies, or wine flies, a reference to the characteristic of many species to linger around overripe or rotting fruit."
Maybe with the exact name someone can help.
Invasive plants are Earth's way of insisting we notice her medicines. Stephen Herrod Buhner
Everyone learns what works by learning what doesn't work. Stephen Herrod Buhner
We have a similar fruit fly here in South America that goes after mangoes (which is why mangoes exported to North America have no taste- they have to be treated in very hot water to kill any potential eggs).
It looks to me like you have two potential routes- decoys (they seem to really go for bitter melon, although that might just encourage them to reproduce and really wreak havoc), or just physical barriers. That page is really long but if you scroll down to cultural controls they talk about wrapping the fruit in newspaper or bags or whatever before the insects lay their eggs.
I have used peppermint iol and water to spray on melons and that helps some, guess they cant smell them. Now I buy throw away hair nets and hospital shoe covers for smaller melons. Get them cheap online by the 100s. Just have to wrap around melons when you see them. They will stretch as melons grow. ( Big watermelons need 2, one from each side).
Good luck, nobody wants to loose a crop after all the hard work.