Abstract-Mobile or pervasive systems continuously change their environments and resources (e.g. battery or bandwidth). Mobile applications require different services when they enter or exit environments and as their resources change. In this paper, we propose a service oriented architectural approach that supports self-adaptation to changes in resources and location topology when mobility occurs, by reconfiguring the software architecture at runtime. The location topology and mobility primitives are inspired from ambient calculus. Our approach considers ambients to be autonomic elements that can manage elements located in them to their environment and provide them with new services suited to the available resources, when mobility occurs. Ambients implement a hierarchical and decentralized MAPE-K loop to adapt the distributed and mobile service oriented architecture to the resource requirements. We have designed an algorithm based on swarm optimization technique in order to allow ambients to optimally plan the reconfiguration process according to available services and resources. Throughout the paper, we use a scenario to illustrate our approach and perform initial evaluations on the swarm algorithm.