If you are holding the charge on a touch spell, will getting hit by melee, ranged attack, or spell dissipate the spell you're holding?
If it's a melee attack, does the attacker feel the effects of the spell you are holding?
The attacker is assumed to have avoided your hand, which is holding a charge of magical energy. You still hold the charge, he is not affected with it. Even if he Grapples you, he’s assumed to be holding your hand away, just as he’d be assumed to be holding a dagger away.
In general, you have to actively try to touch someone to trigger it. It requires an attack action on your part, an attack roll, and so on. In a Grapple, you have to win a Grapple check to get an attack.
A free, retributive effect like you propose is quite rare in 3.x, and usually quite weak. To be able to do it with just any touch spell is potentially overpowered and opens up shenanigans that are probably inappropriate.
The spell-storing property can, in Pathfinder, be applied to armor to do something similar, but
I would assume that when someone is holding a charge for a touch attack, the touch attack wouldn't do anything to an attacker normally. The only circumstance in which it might cause something is if they touched the hand holding the charge, or you touched them. An attacker with a weapon would most certainly not discharge the touch attack. The only time a touch attack's charge is dispelled is if the hand which holds the charge (or item or weapon in the case of channeling) actually touches a valid target.
Though that does bring up an interesting idea... Channeling a touch spell into your armor or shield as a defense, possibly even sending it through an opponent's weapon... Will have to look into the rules for channeling touch spells through items...