A count can call on the Baron to help you defend your town, but only if he has the means for it. Until than you can only muster an NPC militia, or your friends to defend it.
A Duke can send soldiers, but that all depends on what kind of attack is happening. Is it war or not. Many things have to be considered. It also depends on how big of a threat it is. Sometimes an attack is just a false flag to divert soldiers away from the main objective.
Remember to pay your taxes ;-)