We propose a web service selection framework by introducing a QoS-based cost function concept. We used this mechanism to choose a few web services from a given service community according to their cost function. Then, we compose them together to find the optimal composite service. The proposed selection algorithms consume only limited system resources and have the characteristics of efficiency, dynamics, and fault tolerance. Hence, the aim is to optimally select component services at run time according to users' preferences and non-functional parameters.