To monitor and control the states of surrounding infrastructures in smart grid, wireless sensor networks (WSNs) have been perceived to play an important role in connecting diverse smart meters. However, it also incurs many challenges on network security. Firstly, for WSNs, as data are stored and maintained by a large number of sensors deployed in a distributed way, it is significantly hard to ensure distributed data security by using traditional security protection technologies that only can provides guarantees for small scale centralized local networks. Secondly, more fine-grained access control should be provided for smart meters to adapt to the requirements of the multiparty communications between smart grid stakeholders. In this paper, we propose a security-aware distributed service composition scheme for WSNs based smart metering in smart grid based on software defined networks (SDN). Case studies demonstrate the feasibility of proposed scheme. To our best knowledge, this paper is the first to realize software defined security architecture for WSNs based smart metering in smart grid.