At some point prior to John Watson's military career ending injury, he served under Major Sholto and evidently successfully fostered a respectful friendship with the man; as Mary Morstan comments, Sholto is one of several otherwise reclusive or unsociable people counted among John's friends.
Sholto's military career ended (and his life was changed forever) after he led a group of men of new recruits, or crows, into battle. Though this was standard army procedure in Afghanistan they were ambushed by Afghan infantry. A brief battle broke out, during which Sholto's face was badly mutilated by an explosive blast. In addition, his ability to use his left arm became highly limited and he was forced to perform most functions one handed. All the new recruits, including the eighteen year old Peter Small, died and he was left as the only survivor. He received the Victoria Cross medal for surviving the battle, but many people viewed him badly for letting the new soldiers die.
Return to Britain
After the incident, James returned to Britain. He lived in a house far out of town and became somewhat of a recluse, as the press and the families of the new soldiers killed in the attacks hounded him. He employed a fairly large number of private staff, including Gail as a gardener, Charlotte as a cook, Tessa as a nurse and Vicky as a maid. He was allowed to retain his uniform due to a special dispensation. In addition he secretly retained possession of a handgun.
John and Mary's wedding
Despite his otherwise reclusive nature, Sholto's sense of honour and his friendship with John, obliged him to attend when invited to John and Mary's wedding, which, as Sherlock notes, is a rare thing, as Sholto now seldom leaves his home. Evidently feeling it most appropriate, as they had met while in the military, he attends in full dress uniform (with the gun concealed in his luggage).
At the wedding, Sholto is attacked by the photographer, who blames him for the death of his brother – the young Peter Small one of the soldiers who died whilst under Sholto's command. Small had successfully seduced each female member of Sholto's staff and discovered the wedding, the one time Sholto would be away from his private security and in a publicly accessible place.
He was nearly killed when Small stabbed him with a thin knife through his belt while supposedly setting up a picture with Sholto in it. The tight belt held the wound closed, delaying the harm caused by the stabbing, allowing the photographer to be far away from the scene and thus appear blameless when Sholto removed his belt and shortly thereafter bleed to dead. His life was saved by Sherlock Holmes who successfully deduced that Sholto was the target of a murder attempt how it was done.
Initially Sholto was tempted to open the belt, arguing that if so many wanted him dead, it would simply be rude to deny them (clearly still haunted by the incident), only for Sherlock to argue that neither of them would ever let themselves die at John's wedding; as it would ruin the day (since John would be highly distressed by a friends death on what should have been the happiest day of his life). Swayed Sholto relented and allowed John to administer the medical care needed to save him.
Sholto appears to be a selfless, intelligent, and brave man, as he was a decorated officer in Afghanistan. He is also an extremely honourable person, and he is unafraid of death and shows no bitterness at the blame placed on him by the families of the men who died whilst under his command. After the incident in Afghanistan, Sholto became a recluse due to the death threats he received from the families of the men who died under his command. For a brief period while under the threat Small's knife wound, Sholto; influenced by the sheer guilt he felt at his soldiers loss and the hatred he received from the families seemed ready to give up and let the knife wound kill him, but his loyalty to his friends (John specifically) stopped him.