Wharton was born into a prominent Philadelphia, Pennsylvania family, the son of Joseph Wharton. He had forsaken a successful business career to become the Lieutenant of Marines for the frigate United States, which was still part of the War Department. He was quickly promoted to captain in August 1798 and served as officer in charge of the vessel's Marine Detachment until the close of the Quasi-War with France in 1801.
At age 36 and a Marine officer for only five years, he became Lieutenant Colonel and Marine Corps Commandant on March 6, 1804. He was the first Commandant to occupy the Commandant's House, Marine Barracks, Washington, D.C.
As Commandant, Lt. Col. Wharton ordered a detachment of Marines to Georgia and Florida in 1811 to cooperate with United States Army troops in an attempt to subdue an Indian uprising.