The external affairs ministry said Ansari had been invited by his Chinese counterpart Li Yuanchao. They will meet June 30. Ansari will call on President Xi Jinping and will meet the leadership of Shaanxi province.
His will be the first high-level Indian visit to China after Narendra Modi became India's prime minister last month.
President Xi is scheduled to visit India this year
On June 28-29, Ansari will attend a special event to mark the 60th anniversary of Panchsheel or the five principles of peace enunciated by Jawaharlal Nehru and Zhou Enlai in 1954. "The visit will strengthen the strategic and cooperative partnership between the two countries," an external affairs ministry statement said.
Ansari's visit comes after Chinese Foreign Minister Wang Yi concluded two days of meetings with the new Indian government last week.
An invite to Modi from Chinese Prime Minister Li Keqiang to visit China was extended and accepted by the Indian prime minister. The dates are yet to be fixed. Wang's visit was Beijing's first contact with the new government, which China said has "brought a new wind of change".
President Xi is scheduled to visit India this year.