Pervasive service composition is useful in many scenarios, for instance, in urban planning or controlled harvest. Currently, there is no standard to develop solutions using pervasive service composition. However, big companies propose their frameworks to develop complex services, but their frameworks are appropriate in specific applications, such as home automation and agriculture. On the other hand, there are different very well-grounded academic proposals for pervasive service composition. However, these do not solve the problems of traditional approaches that are appropriate to specific areas of application, and adaptation is needed to deal with the dynamism of the environment. This article presents a cognitive approach for pervasive service composition where InfoCom devices and the implementation of cognitive functions interact to create pervasive composite services. Our central hypothesis is that cognitive theory can help solve actual problems requiring pervasive service composition, as it addresses the above-mentioned problems. To test our approach, in this article we present a case of urban insecurity. Specifically, in different countries, street robbery using firearms is one of the problems with a high impact because of its frequency. This article proposes to compose a pervasive service for deterring criminals from committing their crimes. The results obtained by simulating our proposal in our case study are promising. However, more research needs to be achieved before applying the proposed approach to actual problems. The research needed ought to address various problems, some of which are discussed in this article.