No doubt, you have once watched an anime or read a manga, only to find constant panty flashes, accidental boob-grabs, embarrassing walk-ins, and many other such events, usually ending up with the girl screaming and injuring the male protagonist, usually by beating him with a blunt object or kicking him out of the window. This is what is most commonly referred to as "fanservice".
Now, fanservice is not new to anime. Many people have pointed out the obvious fanservice in Cutie Honey (1970) - and it's prominence in the mahou shoujo genre - or Neon Genesis Evangelion (1995). The point here being is that firstly, fanservice is by no means a new topic. And secondly, that fanservice doesn't have to be the most common variant (semi-nudity, panty flashes etc.), but it can also be simply appealing to what the fans want.
In my opinion, fanservice is good when it's supposed to be there. For example, a quick flash of le titties from Rias in HighSchool DxD wouldn't look at all out of place, nor would a questionable choice of camera angle in Rosario+Vampire. What would look out of place, is for example a sudden wind gust blowing a skirt up in a series like AnoHana or Higurashi.
The point I'm making here being, that fanservice can be positive, if applied correctly and in the right environment. It can also be detrimental to the show, if executed poorly and in the wrong type of show. There's only three environments which I believe should have fanservice (of the sexual kind), those being:
And then there's the topic of non-sexual fanservice, as in appealing to fans. I personally like this in my anime, however there's also places where it doesn't fit. For example, the absolute king of fanservice (as of 2016) is the Fairy Tail series. Fairy Tail, as of December the 18th, has had 7 OVAs, 2 separate series of 175 and 102 episodes each (277 eps.), 1 cross-over special, 1 movie and 1 15-minute movie special, a long-running manga and several light novels. It's been more than successful basically. And how has it achieved this? Well, keep a look out for my new post titled "How Fairy Tail Became What It Is Today", although in short, it is a shounen series which does exactly what it's demographic wants. Plot armour, sexual fanservice, cool lore, exactly what the word "shounen" describes.
I think that after a while, it gets a bit tedious. But with shows like Lucky Star (just one big pile of non-sexual fanservice), it's really quite to distinguish what is useful and what is detrimental. Lucky Star enjoys over 24 episodes and an OVA, and many times references popular anime, even making jokes about them, otaku culture, Konata's behaviour, and it pairs in fantastically with the premise of the show.
On the topic of sexual fanservice, you might be thinking "Oh, well why do studios do this? If people don't like ridiculously unnecessary random animu tiddies flying over the screen when they're trying to watch an action scene, then why do they still do it?". And that question has a very simple answer, one that's been observable for decades, if not centuries. Sex will sell. No matter how much work you put into your project, adding just once scene of a bra flying off and a seductive wink will add just a tiny bit of popularity potential. Why? Well, the main demographic of anime is teenage boys and younger children, and with the obvious growth of hormones, what more will satisfy this boy than a catgirl flinging her panties off set? This poses two problems, the first being that some studios with very good ideas that people would truly want to see don't have the appropriate funding to bring their idea to life. The second problem is when some studios focus on making super-fanservice-heavy anime, just to cash in on the whole concept of teenage boys being the main demographic.
I have aggregated a list of commonly seen examples of fanservice that have made their way into the world of anime and manga: