Select to view content in your preferred language

Check if map service is running or not from Silverlight API

3033
6
04-18-2011 02:55 AM
JaskiratAnand
Emerging Contributor
Hi,

can I some how check if my map service is running or not before loading my map control. If teh map service is down and the user runs the application I get the following stack trace:
at ESRI.ArcGIS.Client.ArcGISDynamicMapServiceLayer.MapServiceInfoInitialized(Object sender, MapServiceInitalizeArgs args)
   at ESRI.ArcGIS.Client.Services.MapService.OnInitialized(MapServiceInitalizeArgs args)
   at ESRI.ArcGIS.Client.Services.MapService.wc_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e)
   at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
   at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)

and the following error message:
Object reference not set to an instance of an object

Any help on the same is will be very useful.
Thanks
0 Kudos
6 Replies
TerryGiles
Frequent Contributor
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.
0 Kudos
ChristopherHill
Deactivated User
You would have to do a web request to the server and check that you didn't get a 404 or some other error.
0 Kudos
JaskiratAnand
Emerging Contributor
do a web request to the server

do you mean that i should try and access the server using soap.
0 Kudos
JaskiratAnand
Emerging Contributor
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.


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.
0 Kudos
TerryGiles
Frequent Contributor
I just stopped all the map services used in my application and I do not get any errors.  Can you post the code that is throwing the error and in what event handler?  I stubbed in a Initialized handler for my dynamic layers and it executes even though the underlying service is not there.

        void DynLayer_Initialized(object sender, EventArgs e)
        {
            ArcGISDynamicMapServiceLayer dlyr = sender as ArcGISDynamicMapServiceLayer;

            if (dlyr.Layers == null)
            {
                return;
            }
        }
0 Kudos
VickyP
by
Emerging Contributor
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.


Hi Jaskirat Anand,

   Did you found any solution for Checking if map service is running or not from Silverlight API? If yes then please share with me, I also tried using InitializationFailed and Initialized event of ArcGISDynamicMapServiceLayer, I am also stopping the MapService but it is not showing dlyr.Layers == null
ArcGISDynamicMapServiceLayer dlyr = sender as ArcGISDynamicMapServiceLayer;

            if (dlyr.Layers == null)
            {
                return;
            }

dlyr.Layers is still having values of the layers in the mapservice.


Thanks & Regards,
Varun
0 Kudos