This paper proposes a new method for the automatic composition of semantic Web services. The proposed method consists in constructing a graph and then searching for a sub-graph of this graph, which will represent a candidate composition solution. First, the method constructs a directed acyclic graph, which represents the functional semantics of the Web services as well as the semantic dependency between the inputs and the outputs of the services. Second, composition sub-graphs that satisfy the functionality requested by a client are searched for and ranked according to certain criteria such as user preferences and QoS. The different sub-graphs found represent different service compositions. Finally, the method selects the best service composition for a given user request. To evaluate the method, an experimental framework that automatically composes services has been implemented. The effectiveness of the method has been demonstrated by using a scenario from the trip planning domain.