In Chinese society, civil servants don't always have the best of reputations - they're often regarded as self-serving and corrupt. A bureaucracy ripe for reform? That was tried in the 11th Century - and it didn't work.

Here's an everyday story from last month. A provincial safety official is caught on camera smiling at the scene of a bus crash. The picture goes viral and internet users post other photos showing the same official wearing a variety of luxury watches.

How could he afford those on his salary, they ask?

The behaviour and competence of China's bureaucrats have defined the state for 2,000 years. But in the 11th Century came a visionary who did something almost unheard of - he tried to change the system.

For the first 50 years of his life everything Wang Anshi touched turned to gold.

To begin with, he came fourth in the imperial civil service exam - quite an achievement, as Frances Wood, curator of the Chinese collection at the British Library explains.

Image caption In 2011, a million people competed for 18,000 civil service jobs nationwide

"There were a series - you have local exams, provincial exams, and then the central imperial exam, so you've got lots of people falling by the wayside at the local exams or the provincial exams, so absolutely the creme de la creme get through to even take the central imperial examinations.

"So to come fourth in the whole of China… think of the size of China. To come fourth out of thousands? Tens of thousands of people? It's absolutely massive."

For centuries the civil service was almost the only way to a better life and families gambled all on getting their sons in.

Some candidates had to spend three days and nights in an examination cell measuring 6ft by 3ft (1.8m by 0.9m), the culmination of years of rote learning.

"The civil service exams developed over the centuries," says Wood.

"The essays were largely to do with the content of the Confucian classics - how do you rule the people? You rule them through good, you rule them through example. It's morality that they're being examined on - their ability to cough up gobbets of Confucian morality."

As History is My Witness Former BBC Beijing correspondent Carrie Gracie presents a 10-part series on figures from Chinese history who reveal something about China today

Programmes can be heard every weekday on BBC Radio 4 at 13:45 BST

Alternatively, listen again on the BBC iPlayer China: As History Is My Witness Download the podcast

The successful Wang Anshi was sent off to administer a southern entrepreneurial city.

You can imagine him on an inspection tour, peering out through the silk curtains of his sedan chair at the stallholders and hawkers.

But after 20 years of this, it was clear to him that writing essays about Confucian virtue just wasn't relevant any more. A civil servant needed a different skill set.

"Under the previous dynasties, the cities were fairly rigidly controlled. Markets were held on fixed days, on fixed points and so on," says Wood.

"By the Song dynasty, you begin to get ordinary city life as we know it. Cities are much freer, so commerce is much freer."

The Chinese economy was far more commercialised than it had ever been before, says Peter Bol of Harvard University, who has written about this period.

"The money supply has increased 30-fold. The merchant networks have spread. Villages are moving away from self-sufficiency and getting connected to a cash economy.

"The government no longer controls the economic hierarchy, which is largely in private hands... it's a far richer world than ever before."

Wang Anshi (1021-1086) Qualified aged 21 as an "advanced scholar" in the civil service examinations

Wrote a 10,000-word memo to Emperor Rensong in 1058 arguing that China's officials were not fit for purpose, and needed better training

Appointed as privy counsellor in 1067, he began to roll out "new policies"

As an economic stimulus, he introduced government loans for farmers, and pumped money into the economy by minting coins

He irritated conservatives by carrying out a land survey to reassess property taxes

He did away with recitation of classics and poetry composition in the civil service exams, instead putting an emphasis on law, medicine and military science

Resigned in 1074, returned to civil service in 1075, then retired for good in 1076 to write poetry Source: Encyclopaedia Britannica

But all this created problems. As large land-owning estates grew, so did the number of people who were unwilling to pay their taxes - and the more rich people evaded tax, the more the burden fell on the poor.

There was also problem with the neighbours.

The Song emperors often found themselves at war on their northern borders. Jin and Mongol invaders were annexing Chinese land, so lots of money had to be spent on defence, and inflation took hold.

The dynasty was plunged into crisis.

But cometh the hour, cometh Wang Anshi, and his programme for a new style of government.

"The pressure of hostile forces on the borders is a constant menace. The resources of the Empire are rapidly approaching exhaustion, and public life is getting more and more decadent," he wrote to the emperor.

"There never has been such a scarcity of capable men in the service of the State. Even if they should go on learning in school until their hair turned grey, they would have only the vaguest notion of what to do in office.

"No matter how fine the orders of the Court, the benefit is never realised by the people because of the incapacity of local officials. Moreover, some take advantage of these orders to carry on corrupt practices," said Wang Anshi.

In 1067 a young emperor came to the throne, hungry for new ideas, and Wang Anshi got his chance.

Once in the top ranks of the civil service, Wang Anshi set about diluting Confucius and surrounding himself with like-minded men. Morality was out, maths and medicine were in.

"He was trying to reform the examination system," says Xun Zhou, a historian at Hong Kong university. "So he got rid of some of the subjects. He introduced more practical subjects, so that enabled people with practical skills into the government."

As is often the case, the good man comes up against entrenched, corrupt bureaucrats who didn't want any changes and they turned the emperor against him Frances Wood, British Library

And once they were in, Wang Anshi asked them practical questions. How can we improve education? How can we improve agriculture? How can we provide credit to farmers? How can we ensure a flow of goods?

The British TV comedy Yes Minister was a big hit when it was broadcast on China's state television. It was subtitled in Chinese but everyone here understood the rigidity, self interest, buckpassing, and infighting at its heart.

The civil service has a way of doing things, and in the 11th Century Wang Anshi was turning it upside down, asking the mandarins to roll up their sleeves and manage every corner of the economy.

He wanted state loans for farmers, more taxes for landowners, centralised procurement. But he was not watching his back. He was too sure of himself and too focused on the big picture.

Then events - a drought and a famine - overtook him. It was the opportunity his rivals had been waiting for.

"You have this clash between someone who is obviously very bright, very brilliant, and then he's faced with these corrupt people who've managed to buy their way in," says Frances Wood.

"As is often the case, the good man comes up against entrenched, corrupt bureaucrats who didn't want any changes and they turned the emperor against him."

Wang Anshi was not the type to compromise - getting other people on side was not his style. But added to that, it would have been dangerous to be seen building a faction. That way, in China, lies disaster.

Image caption Officials have dominated Chinese life for centuries

"If the emperor perceives that there's a group of people, a group can grow into something bigger, and I think it's almost more dangerous to be part of a group than it is to be a lone figure crying wolf," says Wood.

"Because you're disgraced, but you can't be accused of being a conspirator."

So it's a difficult game to be a reformist in China. It's safer to stick with the prevailing wisdom, and keep your head down.

Wang Anshi retired in 1076, depressed by demotion and the death of his son. He spent the final years of his life writing poetry.

In the 20th Century some communists hailed him as an early socialist. But for nearly 1,000 years he was the black sheep of the bureaucracy, and the failure of his reform programme, a cautionary tale.

"By and large, Wang Anshi remains an example of what not to do," says Bol.

"There is this radical turn against increasing the state's role in society and the economy. And it doesn't happen again until the 20th Century.

"Because in the 20th Century, the communists picked up some of Wang Anshi's ideas again and rescued his reputation."

Children in Chinese schools today are still under huge pressure to do well in exams. No change there from Wang Anshi's day.

But young people now have more choices in life. The civil service is only one career path.

And the public perception that some bureaucrats are more concerned with their own fortunes than that of the country is leaving an "increasingly sour taste" according to Jonathan Fenby, author of a History of Modern China.

"A local newspaper, magazine, did a survey of what primary school children wanted to be when they grew up," he says.

"So they all said a pop star, or a rich person, or a footballer, or whatever it might be, and one six-year-old girl said, 'I want to be an official.' And the reporter said, 'Oh that's wonderful, yeah, finally somebody wants to serve the State. What kind of official?' And she said, 'A corrupt official, because they have all the nice things.'"

When six-year-olds start talking like that, any mandarin knows the system is in trouble.

The communist mission statement is ruling China for the people, after all. The leadership will change hands next month, but there is no sign of a Wang Anshi among them - someone ready to risk their career by turning the bureaucracy upside down.