Sorry to respond so late to this post. I have two suggestions:
1. Is your map service tiled as in the example? If not, you should change it to "ArcGISDynamicMapServiceLayer".
2. Instead of referencing your map service as "localhost", try the fully qualified domain name of the server, or even the IP address.
Good Luck!