I have the same problem. I took my switch apart and will try to clean it (mine was dropped in water by previous owner).
If that don't work, a new cable harness (including the switch) costs £4.99 on eBay UK (seller phaetondvip88 - I've bougth from them before and are very satisfied). The harness is labeled as 'Apple iPhone 3G Head phone Audio Jack Flex Cable' in their shop...
But, I'm going to try clean it first... Just need to go out and buy some 'electrical cleaning solvent' or whatever it can be named :)