<esri:Map x:Name="MyMap" > <esri:ArcGISDynamicMapServiceLayer ID="MyLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" InitializationFailed="DynLayer_InitializationFailed"/> </esri:Map>
void DynLayer_InitializationFailed(object sender, EventArgs e) { Layer lyr = sender as Layer; MyMap.Layers.Remove(lyr); }
do a web request to the server
Add a handler for the InitializationFailed event on each layer in your map.
XAML<esri:Map x:Name="MyMap" > <esri:ArcGISDynamicMapServiceLayer ID="MyLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" InitializationFailed="DynLayer_InitializationFailed"/> </esri:Map>
C#void DynLayer_InitializationFailed(object sender, EventArgs e) { Layer lyr = sender as Layer; MyMap.Layers.Remove(lyr); }
I know this does not really answer the question as to checking if the service is running or not but should prevent the error and will remove the broken layer from the map.
void DynLayer_Initialized(object sender, EventArgs e) { ArcGISDynamicMapServiceLayer dlyr = sender as ArcGISDynamicMapServiceLayer; if (dlyr.Layers == null) { return; } }
have already done that but the point is that if your service is down the layer initialization won't even begin, the exception will happen while map service initialization, which is what I'm trying to capture.