It happens all over the place, and I am sure that men in a female dominated environment have the same problems but its just not seens as such a big issue for them.
In my experience most of the guys I work with at first just did not know how to deal with a woman at work in an engineering / production role. Bear in mind that other than the odd secretary and other support staff many may NEVER have worked with women in this role before. Its odd to them and often they just don't know how to behave. From this I have seen two distinct and separate responses, one is to treat you like you are their wife / mother / daughter. So they don't swear in front of you, are very carful, don't invite you out, don't involve you in their office 'games' (e.g. lottery, annual sweepstake, night out) because they don't know if you're interested and are too scared to ask. This may sound good because everything is above board and they're very well behaved but it is very alienating, you are very alone because you are not one of them and getting into the group is then very difficult.
The alternative is that they don't change behaviour at all, and treat you just the same way as they would any bloke joining in that position. You get the swearing, the slightly inappropriate comments , the practical jokes. Again, they just don't know what to do with you as you ARE different, whether you like it or not.
From experience of both, both are very difficult to deal with but face it you are different and many of the men you work with don't do it intentionally they just don't know how to deal with it.
My advice, give as good as you get... when the comment ' I know you're a girl but....' I have found that a ' my god, you noticed !' or a 'the boobs just give it away don't they' kind of comment makes them realise how stupid and daft the comment is, and will also make the other guys laugh. You're one of the gang but you don't have give up your femininity.
With regards to your bosses, its a trickier one. I would suggest one of two tacks. First work damned hard, face it you have to be better than your equivalent male colleague often to get noticed, anything average is seen as being not good enough. And if there are things you want to be involved in but aren't asked then ask ! Maybe they don't think you're interested, you wouldn't want to get your hands mucky, you wouldn't enjoy it.
Much as you like to think that there is equality nowadays, it doesn't yet exist. In my experience not because men aren't willing but because they often just don't know how to act around females in that position. Once they get used to it you'll usually have no problems, but stick up for yourself, rise above it and make the job what you want... you don't get if you don't ask.
If you really hate it, get another job. But I would avoid the harrassment aisle unless it is directed at you and is a major problem. Its a lot of hassle and while it shouldn't be it is a very enduring Black mark against your name.
Oh and for reference I think the male female balance where I work is 340:1 excluding clerical staff (170:1 if included) and the dept I work in now has NEVER had a woman work there before except the cleaner / secretary.