On 14 October 1799, at the age of 18, he was commissioned Midshipman by his uncle, George Washington. During offensive operations against Tripoli in 1804, he served in "Gunboat No. 6", commanded by Lieutenant John Trippe. In a stirring attack 3 August against a larger enemy warship, the two officers with only nine other men boarded and took the enemy ship in hand-to-hand fighting, although outnumbered three to one. Midshipman Henley also took part in several other attacks in the months that followed as Commodore Edward Preble's squadron carried out aggressive and successful operations against the Tripolitan pirates that made them ready to end their aggression.