Spaying or neutering your dog should reduce urine-marking and may stop it altogether.
But if they have been marking for a long time, a pattern may already be established.
Because it has become a learned behavior, spaying or neutering alone won't solve the problem.