Internet of Things has been rapidly developed and popularized in recent years, but the serious coupling between application and sensing devices makes development processes quite difficult and complicated. Due to the limitation of original OSGi in sharing services among different nodes, a distributed lightweight middleware structure is proposed based on OSGi. In this distributed OSGi structure, various kinds of functions provided by networked devices are abstracted to services. So that we can take advantage of SOA to manage all networked nodes/devices using services form for decoupling. Single service provided by nodes/devices may only have limited function, and networked devices have mobility and endurance ability limitation, etc. In order to adapt to dynamically changed network and application requirements, a service composition mechanism named DscGOM is designed. DscGOM includes service composition path choosing mechanism and service redirection mechanism. The experimental results show that DscGOM mechanism can be faster and more effective than traditional method, which generates the composition path of services to satisfy the dynamic network demand. When a network device dies or exits unexpectedly, the mechanism can quickly get an alternative composition path and restore the execution.