When I was growing up, the Vietnam War was being fought and then ended. Soldiers weren't popular then, and people didn't walk around saying "thank you for your service".
I first heard that quip after Gulf War 1 in 1991 and have heard it ever since, but I've always felt uncomfortable on those few occasions when it's been addressed to me. First, it seems a little frivolous, as I didn't do it for you, I did it for me! I served because I wanted to do my part for the nation, nothing more, and I certainly didn't ever expect strangers to thank me for it. Second, I don't really know how to respond--"you're welcome" just doesn't sound right given the circumstances, knowwhatimean?
I think I've come up with an appropriate response: should anyone again thank me for my service--which ended 24 years ago!--my reply will be "It was a privilege." Its two advantages are it's not trite, and it's true.