After training as a cadet in the Officers' Training Corps, Rayner was commissioned as a second lieutenant on 14 April 1915, serving in the 1st Battalion, Northumberland Fusiliers. He was confirmed in his rank, and promoted to lieutenant on 3 November 1915. Rayner relinquished his acting rank of captain in the Fusiliers on 16 January 1917, and on 22 February was appointed a flying officer in the Royal Flying Corps with the rank of lieutenant, with seniority from 18 January 1917. He first served as an observer in No. 52 Squadron RFC, before training as a pilot, receiving Royal Aero ClubAviator's Certificate No. 5535 on 10 September 1917, and being appointed a flying officer the same day. Rayner was posted to No. 89 Squadron RFC, a recently formed training unit based at Catterick, Yorkshire, which was eventually disbanded in July 1918 without becoming operational. With the Army's Royal Flying Corps and the Royal Naval Air Service having merged to form the Royal Air Force on 1 April 1918, Rayner then joined No. 60 Squadron RAF, based in France, to fly the S.E.5a single-seat fighter, being appointed flight commander of 'A' Flight on 1 August 1918, with the temporary rank of captain. He gained his first aerial victories on the evening on 5 September when he set one German Fokker D.VII aflame and drove another down out of control over Avesnes-le-Sec. On the afternoon of 23 October he drove another one down out of control over Salesches, and on the morning of 25 October he set a D.VII afire and drove another one down out of control over Berlaimont to become an ace.
Inter-war career
On 17 January 1919, Rayner was transferred to the unemployed list of the Royal Air Force. In July 1919 he received a mention in despatches from Field-Marshal Sir Douglas Haig, former Commander-in-Chief of the British Armies in France, for "distinguished and gallant services and devotion to duty" during the period 16 September 1918 to 15 March 1919. He finally resigned his commission in the Northumberland Fusiliers on 1 April 1920, retaining the rank of lieutenant. Rayner then returned to his legal studies, and qualified as a solicitor. On 10 September 1929, he returned to his military career, being commissioned as a probationary flying officer in Class A of the Reserve of Air Force Officers. Six years later, on 10 September 1935, he transferred to the Class C reserves.
World War II
He returned to active service during World War II, still serving in the Reserves, in which he was granted the war substantive rank of flight lieutenant on 6 August 1940, and received his second mention in despatches from the Air Officer Commanding-in-Chief on 24 September 1941, by which time he had been appointed an acting-squadron leader. He relinquished his commission in the RAFO on 15 September 1943, on joining the Royal Air Force Volunteer Reserve with the rank of flight lieutenant. He was again appointed an acting-squadron leader, and this was made war substantive on 6 March 1944. Two days later, on 8 March, he received his third mention in despatches. Rayner relinquished his commission on the grounds of ill-health on 21 December 1944, but was permitted to retain the rank of wing commander. Shortly afterwards, in the 1945 New Year Honours, Rayner was made a Member of the Order of the British Empire. After the war returned to the law, and by the time of his retirement was also a Justice of the Peace.