Improve Resource Directory

* Fix remote resource serialization
* Fix context url
* Make the resource registration idempotent