Software development in wireless sensor networks has traditionally focused on stand-alone applications statically linked with the operating system code, and relying on fixed models for scheduling, synchronization, and resource allocation. Middleware services and network protocols, are usually considered to be part of the operating system. As the number of available WSN platforms and operating systems grows, and the emergence of cyber-physical systems results in the creation of networks of hetrogeneous devices (sensor nodes, microcontrollers, mobile devices, etc.), portability and interoperation emerge as major considerations in the software development process. We propose breaking the tight integration between middleware services and the operating system. We demonstrate how adopting a service-oriented computing approach to WSN middleware services improves portability and enables the creation of heterogeneous sensor networks and cyber-physical systems. The adoption of a service-oriented architecture does not necessarily translate into a significant loss of performance. An extremely lightweight and flexible method for local and remote service interaction is proposed.