HAVANA -- Twenty-eight years into a revolution that in large measure was a reaction to the free-spending excesses that went with massive U.S. tourism, Cuba has invited dollar-bearing travelers back under conditions that echo the repudiated past.

The numbers as yet are small and the facilities limited. But tourists ride through the tropical night in air-conditioned buses and taxis that Cubans know they must not hail. They dine in restaurants as exclusive in their way as the yacht clubs of old, and they stay in hotels where the only Cubans allowed are those working for the Yankee dollar.

President Fidel Castro in his anniversary speech July 26 ringingly affirmed that the revolution had replaced houses of prostitution with child-care centers, but street walkers again are on the prowl where tourists dwell.

Teen-aged males bent on buying flashy goods in dollars-only shops, through friendly foreign intermediaries, operate a curbside black market with an exchange rate five or six times more favorable to foreigners than the absurdly artificial official one.

A law forbidding ordinary Cubans to possess dollars is strictly enforced, but the main reason the black market is not more entrenched is that Cuba has almost nothing that can be bought with pesos that tourists find worth buying. Export-class cigars and rum of the slightest age are on sale for dollars only.

All of this has the eerie tinge of a period film, authenticated in time by Cuba's rolling museum of American cars that were orphaned on the streets when the United States imposed a trade embargo in 1964. But Castro is not trying to roll back the revolution.

This return to tourism reflects a risky response by Castro, surely painful for him, to the island's persistent failure to earn foreign exchange sufficient to maintain economic independence. It comes as the Soviet Union begins to limit the financial aid -- estimated by the State Department at $10 billion since 1961 -- that until now has permitted Cuba to hoard its primary natural resource, the Caribbean beaches such as the world-class one in Varadero that now is abustle with foreign bathers.

The changes, startling to a visitor returning after an absence of 20 years, also signify a gamble by Castro that after more than a generation of creole communism, the new Cuban can profit from international tourism without being seduced by it as in the past.

By all indications, Castro is prepared to stay the course. But as the inflow gradually has increased, so have bottlenecks. And contradictions so far are more obvious than accomplishments.

Cuba has added only haphazardly to the tourist facilities extant in 1959. The hotel-gambling casino complexes that then attracted Americans are rundown, musty, even a bit funereal. The staffs are often embarrassingly inept as the government tries to train faithful young communists to replace the specialists in tourism who have long since reestablished themselves in Miami.

"The service is awful," acknowledged a Cuban official of middle rank, who argued that in any case the country is trying to attract not the elite tourists but those with limited dollars and perhaps a political interest in the island.

Prices are comparatively low: $25 a night for a couple in a clean walk-up hotel in Varadero to about $65 at the International up the beach or at its Havana counterparts. But samplings reportedly indicate that the Canadians, West Europeans and Latin Americans being particularly sought tend to come only once.

The two-tier economy of dollar spenders and peso spenders, necessary because Cuba is hopelessly distant from being able to exchange its currency freely in international markets, seems especially corrosive for the young communists on whom the revolution ultimately depends.

A strapping young Cuban, for instance, employed to dance with women tourists in a state-owned bar in the dollar-driven resort of Varadero, confessed in an after-hours aside that he wished to leave Cuba. Furthermore, he voiced the allegation usually heard only from the most militant anti-Castroites, that "if they opened the gates again in Mariel {from which about 125,000 Cubans fled to the United States in 1981}, this time a million would leave."

The Mariel experience is itself widely interpreted to have been a consequence of an earlier, limited experiment in tourism here. Under the Carter administration, when the United States and Cuba restored limited relations, tourism briefly burgeoned. Cuban Americans returned for the first visits to their homeland since they had fled in the early years under Castro.

The relative affluence of these visitors was a shock to Cubans in their spartan circumstances, and they began seeking refuge in embassies as a way-station to exile in the United States.

The young dancer, perhaps because of the nationalities of the people he meets in his work, said his goal is not the United States but Western Europe or perhaps Canada. As with other Cubans working in this sensitive industry, he was chosen because of his dependability.

A bartender, more openly loyal to the revolution, said he longed to go to Buenos Aires in search of an Argentine who took her leave from Varadero after their last tango in the spring. In a late-night session over bottles of Hatuey beer, the several Cuban bar workers did not question each others' loyalties but did argue vociferously, with decided dialectic, about the inequities of a system that excluded other Cubans from their midst.

Even the Hatuey beer was a hint of change encouraged by the revival of tourism. Until recently, Castro's government responded to the Cuban predilection for beer by producing one no-name brand, in unmarked amber bottles, rarely in sufficient quantity. Supplies are still short, but not for foreigners, and the prerevolutionary brand name of the Indian chief Hatuey is back as the premium in a family of beer brands.

In another conversation, a young Cuban in a managerial position in Varadero's tourist industry cringed at the conflicts between the ideological rigor of his party role and the seaside languor of his current surroundings. He, as it happened, was drinking a Miller beer, a favorite at 50 U.S. cents per can, brought into dollar-thirsty Varadero through some third country despite the embargo.

"We will do what we must for tourism, but it will be on our terms," the manager said, reflecting the confusion he felt in his new assignment. His last work, he said, was as an English instructor, but in fact he spoke almost no English.

A three-day, 600-mile car tour of the island's central sector offered opportunities for conversation with almost two dozen other young people -- hitchhikers dealing with the shortage of public transport. This sample suggested that rural students and Army recruits on leave, with their less complicated perceptions of the ideals propounded by Castro, are far more loyal to the revolution than people exposed to foreigners.

"I don't like the Army, but it's my duty," said a young veteran of service in Angola, on his way to home leave in the Escambray before a second tour in Africa. Others in the service expressed similar sentiments.

The fact that an American journalist can rent a car and travel unaccompanied around the island is a measure of how basic a change the move toward tourism entails.

The official tourist agency Intur captures every possible dollar up front. Gasoline is rationed but the tourist buys whatever he needs with prepurchased dollar coupons.

Twenty years ago, a trip to the provinces was possible only in the company of Communist Party guides. The security measures so massive then are scarcely noticeable now. Indeed, the Interior Ministry's police apparently are under orders to be permissive with foreign tourists.

For years, the largest contingent of foreign tourists has been Canadian. According to official Cuban figures, the inflow of visitors gradually increased during the first years of this decade to a total of 173,000 in 1985, of whom 40,000 were Canadian. Another 65,000 were West Europeans, mainly Spanish, Italians and West Germans. About 27,000 were Latin Americans, mostly from Mexico. About 27,000 were from the East Bloc, but without hard currency they came to a most restrained welcome. U.S. tourists -- discouraged by federal restraints on financial transactions in Cuba -- accounted for 1,200 of the remainder.

Special efforts have been made to attract tourists from Brazil, which recently resumed relations with Cuba. Air routes often are indirect, with transfers in Panama. The special category of Cuban Americans remains a delicate one. Under U.S. regulations, people with family in Cuba are free to travel.

But since Mariel, Cuba has limited those given visas to 2,500 closely checked travelers per month. A couple of crowded charter flights go weekly from Miami, around midnight. The Cuban Americans carry astonishing quantities of the myriad items that are in short supply here. The tape decks, VCRs and hair driers are helping to change the face of revolutionary Cuba.