Here's a few general tips:
Always try to be at full health and ammo. It doesn't matter if you're at 189 as soldier, get a health pack. Although, try not to use a large health pack for a small amount of health, as you or someone else may need it later. Something that's good to remember:
Large Health Pack restores 100% of your hp
Medium restores 50% (Half) of your hp.
Small restores roughly 1/5th of your hp (20.5%)
The same goes for ammo/metal.
Always, always, always spycheck. Everything is a spy, even that rock. I've gotten a few invisible spy headshots by just shooting down a hallway.
Always be aware of your surroundings. Know the map you're playing, and plan how to receive your enemies. Don't just focus on one person if you know there's a heavy medic around the corner. If you're alone and you don't think you can take on the enemy, then run to a place where there are many of your teammates, even if you are at full health.
Position yourself for ambushes. Once you know where he's coming from you can easily position yourself to take him by surprise, especially if you're a soldier. Rocket Jumping is a very valuable skill.
For demo, I like to set a trap where the enemy can't see it and then use my pipes for everything else. Learn to aim with pipes, they're really good.
For heavy, you're a bit slow, so you shouldn't overextend. Always be in a position where you can easily meet up with your teammates. Despite your high hp, you're actually an easy target if the enemy knows what he's doing.
One last thing: Move. It's not just your mouse and the w key. Move left, right, up, down, and diagonally. If you do this the enemy can't hit you.