Wireless sensor networks are application specific, data centric networks where different applications run on deployed network. Each application interprets the underlying sensor network differently and each changing event has different effect on running applications. In this paper we have proposed context aware middleware architecture called as ’MidSen’. This architecture bridges the gap between multiple applications running at application level and deployed sensor networks. MidSen architecture handles static as well as dynamically changing network and application components. MidSen has adopted a rule based engine to handle system dynamics. Midsen makes applications flexible by allowing them to update their rules against knowledge base. Our experimental results show that proposed Context Aware Service Discovery (CASD) algorithm gives better recall value and precision compare to previously proposed discovery algorithms.