Washington's labor unions chose sides yesterday in the race for mayor, with the major public employe unions endorsing Mayor Marion Barry and building trades and other private sector groups backing Patricia Roberts Harris, Barry's chief rival in the Democratic primary.

It was a day of dueling endorsements in which both candidates--neither of whom had been able to secure the unified support of organized labor at a Monday night meeting--claimed to have won the hearts of union members.

Barry, looking bouyant and confident, was endorsed at a morning press conference at the International Hotel by officials of six major labor groups that represent an estimated 50,000 city-dwelling government workers, teachers and service, postal and communications workers.

Many of these union leaders once bitterly denounced Barry for laying off city workers, slashing the city budget and battling striking teachers. But yesterday they heaped praise on a mayor they said had "grown in the job" and granted them major concessions in the latest round of contract bargaining.

"We are not about to throw four years of hard work down the drain by switching mayors in midstream," said Kenneth T. Blaylock, national president of the American Federation of Government Employees (AFGE). "The other candidates might be attractive, vocal and superstars. But Mayor Barry has produced substance for not only us, but for the city in general."

William H. Simons, president of the Washington Teachers Union and an ardent critic of Barry's action during the 1979 teachers strike, threw his arms around Barry yesterday in offering his support.

"One does not want to be myopic . . . but one must look at the needs of the city as a whole in making an endorsement ," Simons said.

Several hours later, Harris was endorsed by leaders of the Washington Building and Construction Trades Council, the Hotel and Restaurant Employees Union, the United Food and Commercial Workers and several other unions representing 30,000 to 35,000 D.C. residents.

"Pat Harris is the only candidate who really cares about workers and hasn't sold out to the Greater Washington Board of Trade," said Ron Richardson, executive secretary and treasurer of the Hotel and Restaurant Employees Union. "And it's time we had a competent mayor . . . I defy anyone to show a more bumbling, bungling, inept administration than Barry's ."

Many of the union leaders said they oppose Barry because he supported changes in the D.C. workers compensation and unemployment insurance laws that favor business over labor.

Robert Parker, secretary-treasurer of the building trades council, complained that nearly a third of the workers on the $99 million Convention Center project were not union members and blamed Barry for this.

He said Barry justified awarding a major Convention Center electrical contract to a Pennsylvania firm that employs out-of-state workers because it submitted the lowest bid.

Yet, Parker said, the same administration recently rejected low bids when it decided to purchase new police cars from Curtis Chevrolet here and to temporarily shelter homeless families in the Pitts Motor Hotel.

Harris criticized Barry for spending three years battling with labor unions before softening his stance to win support for his reelection campaign.

"I will not wait till the year before an election to see that the needs of the trades unions are met," she said.

The race for mayor has bitterly divided labor groups. Harris allies claim that the mayor has ruthlessly exploited his office to win labor support and Barry partisans claim Harris was inaccessible and hostile to labor when she was secretary of Housing and Urban Development (HUD) and Health and Human Services.

Yesterday, Harris denied an accusation that in 1980 she crossed an AFGE informational picket line in Baltimore set up to protest her refusal to intervene in stalled contract talks between the AFGE and the Social Security Administration.

Harris said the picket line was set up by the union after she had entered the building to attend a dedication ceremony.

Labor groups repeatedly have failed to elect candidates for mayor and D.C. City Council in recent years, although more recently they displayed some muscle in helping to defeat an education tax credit initiative last fall.

Barry won election in 1978 with the support of only three unions--those representing teachers, police and firemen. Most other unions sided with then mayor Walter E. Washington.

Union leaders who took part in yesterday's endorsements pledged to raise funds for Barry and Harris and to use telephone banks, leaflets, direct-mail appeals, voter registration and get-out-the-vote drives in providing support.

Joining the AFGE and the teachers union in endorsing Barry were representatives of the American Federation of State, County and Municipal Employees (AFSCME), the Service Employes International Union, D.C. Postal Workers and two local chapters of the Communications Workers of America (CWA).

Several other CWA locals endorsed Harris, as did scores of trades unions, including the plumbers and pipefitters, operating engineers, steamfitters, electrical workers, laborers, stone and mason workers, asbestos workers and cement masons.

At-large D.C. Council member Betty Ann Kane and Ward 4 Council member Charlene Drew Jarvis, both Democratic candidates for mayor, said yesterday that the labor endorsements for Barry and Harris may have canceled each other out. Council member John Ray, the other major Democrat in the race, was unavailable for comment.