Christ Church in New Mill was full of Cpl Hartley’s friends and family, with dozens more mourners assembled outside.
Relatives gave readings during the service, which was led by the Rev Canon Sean Robertshaw.
Cpl Hartley was killed along with five others when their vehicle was struck by an improvised explosive device in Afghanistan last month.
Outside the church Major Mally Birkett from the 3rd Battalion The Yorkshire Regiment paid tribute to Cpl Hartley.
He said: “Cpl Hartley was an infantry man to his core – tough, proud, hard-working and honest.
“The battalion has lost a fine soldier and an outstanding leader.”