Just like when facing melee attacks, dwarves can parry (based on weapon skill), block (with a shield, using Shield User skill), or dodge (using their Dodge skill) incoming missiles. If they get hit after all that, the projectile still has to strike through their armour.
The best solution is to have highly-skilled, fully armoured dwarves - set your militia training as soon as possible, and make sure you can kit them out with appropriate armour (you need to cover as much as possible, so I think a minimal optimum approach would be a mail shirt, helm, gauntlets, greaves, high boots, and a robe). Sparring supplemented with 'live' exercise on wildlife / thieves / "volunteers" from cage traps should get your dwarves to legendary in their weapon skills within 1-2 years maximum.
Alternative options include having a checkerboard style grid before your entrance so that vision ranges are restricted (this does however mean your depot needs to be elsewhere or won't get wagons), the usual trap setup (goblins with no arms don't shoot very well, I've noticed), or having lots of alternative targets for them to shoot (you didn't really need all those puppies anyway, right?).
Be careful if you use fortifications - anything standing adjacent to a fortification can shoot through it, and Elite types can shoot through them at a greater distance, so don't skimp on Marksdwarf armour and training!