Pervasive computing applications typically involve rich interactions and heterogeneous network types; e.g. involving the collation of data from a sensor network into a replicated repository in a fixed network. Although the middleware approach has been highly successful in supporting application development in networked environments, current middleware technologies cannot handle the accelerating complexity in interaction types, and diversity in networks types, seen in pervasive computing environments. Therefore, we propose a middleware solution (called Gridkit), which uniformly supports an extensible set of middleware interaction types (e.g. RPC, publish-subscribe, streaming, etc.), and handles network heterogeneity by layering itself over virtual overlay networks which it manages and transparently instantiates on demand. We focus in this paper on Gridkit's generalized architecture for the transparent deployment and management of overlay networks. We also consider the application of the Gridkit approach in two application scenarios.