In dynamic ubiquitous computing environments, system entities may be classified into two main categories that are, in principle, in conflict. These are the Service Resource Requestors (SRRs) wishing to use services and/or exploit resources offered by the other system entities and the Service Resource Providers (SRPs) that offer the services/resources requested. Seeking for the maximisation of their welfare, while achieving their own goals and aims, entities may misbehave (intentionally or unintentionally), thus, leading to a significant deterioration of system's performance. In this study, a reputation mechanism is proposed which helps estimating SRPs trustworthiness and predicting their future behaviour, taking into account their past performance in consistently satisfying SRRs' expectations. Thereafter, under the assumption that a number of SRPs may handle the SRRs requests, the SRRs may decide on the most appropriate SRP for the service/resource requested on the basis of a weighted combination of the evaluation of the quality of their offer (performance related factor) and of their reputation rating (reliability related factor). The proposed trust management framework is distributed, considers both first-hand information (acquired from the SRR's direct past experiences with the SRPs) and second-hand information (disseminated from other SRRs' past experiences with the SRPs), while it exhibits a robust behaviour against inaccurate reputation ratings. The designed mechanisms have been empirically evaluated simulating interactions among self-interested agents, exhibiting improved performance with respect to random SRP selection.