Abstract-Service composition in sensor networks combines elementary services with a specific functionality to create a service with higher level functionality. The previous efforts in automating composition were sending full information about all services across the entire sensor network, creating a security risk and imposing significant communication overhead. Furthermore, learning based composition or error detection methods do not consider global information, leading to inefficiencies in the generated composition graphs. In this paper, we propose a probabilistic context-free grammar (PCFG) based modeling technique to construct service compositions. The successful compositions created for the given application are treated as statements belonging to an efficient composition PCFG of this application. The given set of such compositions is used to derive this PCFG automatically. Future composition could be then easily constructed with the help of such PCFG. We present our methodology for achieving such modeling and provide examples of its use to demonstrate its advantage over previous work. We also evaluate the resulting improvements in performance of compositions and in the costs of their creation.Index Terms-sensor networks; service composition; PCFGs;I. INTRODUCTION Service oriented architecture (SOA) for wireless sensor networks (WSN) have recently been proposed as a means to abstract the sensor network as a set of services (programs integrated within sensor nodes) that provide a certain functionality. In this context, the task of service composition is to efficiently combine a set of services so that a more complex functionality can be realized. In our initial work for SOA for WSN [1], we showed how to represent a composition as a graph of connection of services and how to automatically combine services in an efficient way. While such an automated scheme improves energy efficiency of the solution, during composition creation this scheme suffers from communication overhead and a security problem because metadata about services are sent between all potential services. Since the metada may include mission critical information, in domains such as military applications, the user may not want such information to be moved around freely. Manual connection of services by the user is a possible solution to this problem that has been followed in the literature. However, such a method becomes error-prone with the increasing composition size.