A wireless sensor network (WSN) consists of a large number of small devices with computational power, wireless communication and sensing capability. These networks have been developed for a wide range of applications, such as habitat monitoring, object tracking, precision agriculture, building monitoring and military systems. Meanwhile, middleware systems have also been proposed in to facilitate both the development of these applications and provide common application services. The development of middleware for sensor networks, however, places new challenges on middleware developers due to the low availability of resources and processing capacity of the sensor nodes. In this context, this paper presents the design and implementation of a middleware for WSN named Mires. Mires incorporates characteristics of message-oriented middleware by allowing applications communicate in a publish/subscribe way. In order to illustrate the proposed middleware, we have also developed an environment-monitoring application and a data aggregation service.