It has been open season against foreign multinationals in China this year, with one attack from the government or state-controlled news media followed swiftly by another.

Drug company executives have been arrested for corruption. Dairy companies have been handed record fines for price fixing and had their imports banned because of tainted milk powder. KFC and McDonald’s were attacked over hygiene, and Apple was upbraided for customer service.

Business for foreigners in China has never been entirely smooth sailing, but the intensity and frequency of the latest salvos have rung alarm bells throughout the business community here. Foreign companies say they feel like scapegoats — in part in reaction to the economic downturn and in part in an attempt to deflect attention from China’s own domestic food- and drug-safety concerns.

Nor is the pressure likely to abate “for the foreseeable future,” complained one leading American businessman, who asked not to be identified to avoid trouble with the authorities. “We are an easy target because we don’t have political backing; we don’t have a patron.”

Yet in China, nothing is ever quite as straightforward as it might seem. At the same time that foreign companies have come under attack, trade bodies that lobby on their behalf say they have been given unprecedented access to high-level government officials, something of a “charm offensive” that has come as a pleasant surprise.

In July, China agreed to restart talks on a Bilateral Investment Treaty with the United States that could significantly improve market access for U.S. companies, although negotiations are sure to be long and tortuous.

Plans to open mainland China’s first Free Trade Zone in Shanghai, with more liberal rules for investors, have also been welcomed, while China has even expressed interest in joining a proposed Transpacific Partnership, a giant free-trade zone that it had originally eyed with suspicion.

The mixed signals “reflect the conflicted attitude that you have towards foreign investment in China,” said Arthur Kroeber, managing director of economic research firm GaveKal Dragonomics. “On the one hand, there is a strong need to have it, but at the same time, there is a little bit of insecurity and resentment about the large positions foreign companies have in hand. So you see China welcoming it with one hand and pushing back with another.”

In a sense, the slowdown in China’s economy only serves to accentuate that contradiction, fueling the resentment toward foreign companies that are doing well here, while underscoring the country’s need to attract fresh foreign money.

In March, state broadcaster China Central Television accused Apple of offering worse after-sales service here than in other parts of the world, prompting the government to threaten tougher regulation. In July, CCTV turned its attention to American fast-food giants, saying its tests showed that ice cubes at KFC were dirtier than toilet water and that those at McDonald’s were not up to drinking-water standards.

Last month also saw the detention of four senior Chinese executives and 18 other employees of British pharmaceuticals giant GlaxoSmithKline on charges that they bribed hospitals and doctors to prescribe their drugs. Other drug companies are also being investigated.

New Zealand diary giant Fonterra announced this month that it had found bacteria that could cause botulism in an ingredient used to make powdered baby milk. The company was attacked by state-run Xinhua News Agency and imports of its products temporarily banned. Several days ago, six foreign baby milk producers were fined a combined $108 million for allegedly engaging in price-fixing, and Xinhua called for a similar investigation into foreign luxury carmakers.

It is no coincidence that most of the criticism has come over food safety and the costs of health care. Those are issues of major concern to China’s emerging middle class, and they have been a focus of unhappiness with domestic suppliers.

In 2008, Chinese milk was found to be tainted with melamine. Since then, consumers here have turned en masse to foreign milk powder, so much so that Hong Kong was forced to limit cross-border trade. Attacking importers has the twin appeal of helping deflect blame from domestic regulators while also helping domestic industry. Similarly, attacking foreign drug companies is easier than addressing the root causes of widespread corruption in the health-care sector, where poorly paid doctors and hospitals are forced to accept bribes to supplement meager revenue.

Politically, though, it is not clear that the campaigns will be effective. China’s legion of social media users often react cynically when CCTV targets foreign brands, pointing out with some justification that Chinese companies are usually far-worse offenders. Chinese consumers, meanwhile, are unlikely to start trusting local infant formula brands, especially given the vast scale and initial coverup of the melamine scandal.

Kroeber said that the new government of President Xi Jinping has yet to properly articulate a clear position on foreign investment, allowing conservatives within the Communist Party a free rein to do what they want. “There is no line that people have been asked to follow,” he said. “That contributes to mixed signals.”

But the change of mood toward foreign companies did not begin with Xi’s accession to the presidency. Some say the turning point was a wave of nationalism unleashed around the 2008 Beijing Olympics, when foreign companies were attacked for supposedly not contributing enough to victims of the earthquake that struck Sichuan province in May of that year. China’s successful weathering of the 2008 global financial crisis also fueled a sense of hubris here, observers say.

Optimists argue that Xi’s government, by going after foreign companies, is merely softening up the population in anticipation of much-needed economic reforms. The attacks, they say, appease the powerful vested interests behind China’s massive state-owned enterprises and private-sector giants but also warn them that they could be next if they fail to fall in line.

“This is a great way to tell powerful industrialists: ‘Don’t give me any grief about upcoming reforms measures. This could happen to you,’ ” said the American businessman. “If these guys felt too comfortable, they could line up in opposition to economic reform.”

It is not an argument that convinces Patrick Chovanec, longtime China watcher and chief strategist at Silvercrest Asset Management in New York, who points out that there has been no indication that attacks on foreign targets will actually be followed by the much tougher challenge of dealing with local industry.

“The idea is that you kill the chickens to scare the monkeys,” said Chovanec, citing a famous Chinese saying. “But are the monkeys ever really scared? They are not chickens.”

None of this means that U.S. companies are suddenly going to start leaving China, a market that remains both important and profitable. Foreign direct investment is still very healthy, reaching $62 billion in the first half of this year, up nearly 5 percent from last year.

More than 70 percent of American companies here still report rising revenue, and nearly half report higher operating margins in China than global averages, according to the latest survey of business sentiment by AmCham China. But it may mean that some U.S. companies think twice before moving more complex manufacturing processes to China, Chovanec said, slowing down the country’s attempts to move up “the value chain.”