It can work if it ties into the story as a whole (in regards to themes, symbolism, and motifs) or if it ties into the character who is the fanservice character (whether they are comic relief or it has something to do with their personality). As an example to each, the fanservice worked in the Ghost in the Shell movie because Motoko's nudity wasn't portrayed as sexy and it ties it into her struggle of dealing with the body she was put into. For a more specific character example, Talho Yuki from Eureka 7 wore skimpy clothes to get her boyfriend's attention when he thought he was Eureka's chosen one. When he eventually realized he wasn't, he began to pay attention to Talho more and since she has his attention there was no need for her wear skimpy clothes anymore. Come to think of it iisn't really fanservice if it works in a story because it is had a purpose and isn't there to pander. If you want to use it as comic relief, usually make it the result of a seductive or pervert who gets punished for his actions. Using the whole "male character accidentally falls on a woman and results in him getting punished" is cliched isn't satisfying because the character getting punished did nothing wrong.