When you publish a map service there is a URL for each layer. The way the URL is generated is very deterministic and it includes several elements including the layer indice which is simply the 0 based index of the layer in the map.
i'm providing a way to allow users to enter any url and add to the map dynamically... i would like to know if the url the user entered is connected(server exists, connection exists, internet connection available), is a valid ArcGIS Server layer, or a KML layer, or a WMS layer, etc.
i would like to verify the url before adding to the Map...
like a web browser.... when you type http://www.yahoo.com.. it is a valid link.. however it is not a valid ArcGIS Map layer......
I think that you just have to call a REST method on that URL to confirm whether or not it is valid. Look through all the methods available and pick one that makes sense.