During the Ming Dynasty, many walls were erected to enclose the city and guard it against Japanese pirates. During the 19th century the walls could not prevent the city from the pry of the British and in 1842, with the end of the opium war, Her Majesties soldiers opened up this port city and set up the first foreign concession in Shanghai, the French followed in 1847, an International Settlement was established in 1863 and a small Japanese enclave in 1895. Thus, at the end of the 19th century, and with no special living permits for foreigners, foreign investment and cheap Chinese labour transformed Shanghai from a small fishing village into a booming port and industrial city. In a way Shanghai was a truly laissez-faire city where anything under the sun could have been bought and sold. Part of the foreign influx into Shanghai, in 1908 Canada opened its first Asian diplomatic office in the city, long before setting up missions in other Asian centers like Hong Kong and Tokyo.
Shanghai continues to be Canada's oldest existing diplomatic presence in Asia.