This paper proposes a service oriented middleware architecture for wireless sensor networks (WSNs) with security requirements. The web services standards XML, SOAP and WSDL are used for network communication. For the WSN security the WS-Security specification is applied, using cryptography and authentication for the data traffic. A prototype developed in Java language tests the proposed architecture. The results obtained show the correct functioning of the middleware, which facilitates the development of secure applications for WSNs.