 For a short time, from February 22, 1879, until he resigned effective on December 23, 1880, Ray was the United States Attorney for the District of New Hampshire.He was elected as a Republican to the Forty-sixth Congress to fill the vacancy caused by the death of Evarts W. Farr and was re-elected to the Forty-seventh and Forty-eighth Congresses, serving from January 8, 1881, to March 3, 1885.Ray did not seek renomination in 1884.