As an emerging solution to latency requirements of Internet of Things (IoT) services, edge computing can bring powerful processing capacity closer to data sources. However, with the limited resources at edge nodes, a major challenge is finding optimal resources in distributed edges to reduce the operational costs of service deployment. Prior works focus mainly on static optimization which may not work efficiently with the time-varying workloads and resource constraints. In this paper, we, therefore, consider a dynamic allocation framework in the edge-cloud network over the long run with uncertainty workloads. In such a system, we introduce a JOint Routing and Placement problem for IoT services, called JORP, that dynamically assigns resources according to workload demand in order to reduce the operational costs in long term. Inspired from the well-known algorithm, branch-and-bound (BnB), for solving the mixed-integer non linear problems (MINLPs) like JORP, we bring the learning concept to address the high complexity of BnB when the search space is huge. Particularly, we design a deep neural network (DNN) and train it under the imitation learning to mimic branching behaviors in BnB for searching the optimal solution. Finally, simulations show our solution outperforms baselines in terms of convergence and operational cost.