China and the Association of Southeast Asian Nations have agreed on a framework of a legally binding code of conduct in the South China Sea following years of negotiations, a senior Chinese diplomat said Thursday.

"We have worked diligently and completed the consultations" on the framework, Chinese Vice Foreign Minister Liu Zhenmin told a press conference after he co-hosted a meeting of senior officials from both sides in the country's southwestern city of Guiyang.

Liu praised it is a "reflection of the positive momentum in the South China Sea and the reflection of the sincere desire by China and ASEAN member states in maintaining peace and stability in this region."

The diplomat said the framework includes preambles of objectives and principles. China and the 10-member ASEAN were trying to reach a deal on an outline of the code in the disputed sea in the first half of 2017.

China claims almost the entire South China Sea. Its rapid building of artificial islands with military facilities in some areas has stoked concerns not only among other smaller claimants, including the Philippines and Vietnam, but also other countries such as Japan and the United States, which Beijing calls "outsiders."

In 2002, China and ASEAN signed the Declaration on the Conduct of Parties in the South China Sea, a looser set of guidelines for their behavior in the area.

They had since been working to upgrade it, but with almost no progress in ironing out differences even over the basics.

For years, ASEAN officials said, China was not cooperative enough, but its Foreign Minister Wang Yi suddenly unveiled to reporters last year the goal of formulating the outline by the end of June.

The goal was announced not so long after the release in mid-July last year of an international tribunal's ruling that rejected China's claims to almost the whole South China Sea.