If it's fleeting due to quick conversation or similar, I let it go the first time. Otherwise I politely say, "I'm a he, actually" and smile, or, "I'm not a ma'am, actually, I'm a sir" if it's a commerce situation. Half the time I'm inwardly fuming but outwardly I am always polite and friendly to people about this.
I do feel it's important to catch, though. I'm still in school so this is not a comparable workplace story, but in one of my classes this semester I was referred to as she/her a few times by one of the students and did not correct it at that time. And it SPREAD in that class. At one point after I was speaking and making a point, another student followed up and referred back to my comment and used she/her, which the teacher then also used. At that point all I could do was speak up and say, "I'm a dude, actually" in as friendly a manner as I could, but having to do that in front of the whole class was kind of daunting. (The student then apologized and was clearly very embarrassed, and I said it was cool)
Anyway, I'm trying to say that if you don't catch this kind of thing immediately, it will continue and other people will start to do it, and it's just ugh.