Returning to the original question, it's definitely between Star Trek and Doctor Who for SF, and which comes out top depends on whetehr you're talkign abotu number of episodes or amount of air time - Doctor Who, particulalrly if its TV spin-offs are included, comes out ahead by a good 100 episodes, but 80% of those episodes were roughly half the length of the average Trek episode.
Outside of SF... Casualty's got to be in the running: 22 seasons of the original series since 1986 at 10 to 40 50-minute episodes a year, closing on 700 episodes, plus nine seasons of spin-off Holby City (more than 350 episodes) and two season of Holby Blue, and 10 episodes so far of Casualty 1906(/1907/1909).
Could the Law and Order franchise maybe beat that? Wouldn't rule it out...
Edit: Another British possible would be Z Cars - 18 years on air, plus one spin-off that ran for 10 years (Softly Softly Taskforce) and another that ran for four (Barlow at Large). Not to mention a series of drama-docs that had the central characters 'investigating' notorious historical cases (Second Verdict).