Service-oriented architecture (SOA) is realized by independent, standardized, and self-describing units known as services. This architecture has been widely used and verified for automatic, dynamic, and self-configuring distributed systems such as in building automation. This paper presents a building automation system adopting SOA paradigm with devices implemented by device profile for web service (DPWS) in which context information is collected, processed, and sent to a composition engine to coordinate appropriate devices/services based on the context, composition plan, and predefined policy rules. A six-phased composition process is proposed to carry out the task. In addition, two other components are designed to support the composition process: building ontology as a schema for representing semantic data and composition plan description language to describe context-based composite services in form of composition plans. A prototype consisting of a DPWSim simulator and SamBAS is developed to illustrate and test the proposed idea. Comparison analysis and experimental results imply the feasibility and scalability of the system.