Detecting and recovering from ArcGISTiledMapServiceLayer svc connection problems

564
5
03-29-2011 12:57 PM
AndySanford
New Contributor
Hi, 

We're using the Silverlight api 2.1 (SL4).  We're trying to figure out how to detect and then recover from problems where an ArcGISTiledMapServiceLayer has trouble talking to its REST web service.  We're seeing problems with two distinct but related scenarios:

1) layer working correctly, talking to service and showing imagery; if you then disable the network adapter, then zoom in or out: layer just becomes blank, and we get no notification of errors (layer.InitializationFailed is not called in this case.)  Is there any way to programatically detect this case, and then recover from it?

2) If, after case #1, we change the URL of the layer (say, because the user wants to see a street map instead of imagery, or maybe because they are confused by the now blank layer), the layer.InitializationFailed then fires if the network link is still down, and so we can now show the user a msg.  After that, once the network is restored, how do we recover (that is, get the layer updating/showing tiles again)?  We've tried calling layer.Initialize() as well as layer.Refresh(), and neither seemed to do anything.  We tried setting the URL to the same URL as it was, and that does nothing.  We then tried changing the URL from one valid address (say, for imagery) to another (say, for street maps) and then back again to the original.  This seems to do something, but not to succeed either; instead, layer.InitializationFailed fires again.  After a few times retrying this recovery method, we get a NullReferenceException in the layer and that's the end of things.

It is reasonable to expect that the connection between a tile layer and its service will become unavailable sometimes, so there seems there would be a straightforward way to detect when problems start occuring (so we can report them) and a way to cleanly recover from the problems once the connection becomes available again.  What is the recommended way to do this?

Thanks!
0 Kudos
5 Replies
JenniferNery
Esri Regular Contributor
In both cases, your app need to subscribe to Layer.InitializationFailed event http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Layer~Init... so you may notify your users when the server is down.

You can use NetworkInterface.GetIsNetworkAvailable() to check your network connection: http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getisnetworka...

We recommend that you create a new instance of ArcGISTiledMapServiceLayer instead of updating the Url property. Every new instance can wire up to the same InitializationFailed event handler. You can call Initialize() after this.
0 Kudos
AndySanford
New Contributor
Thanks for your response.  I will look into recovering for #2 by creating a new layer.

In both cases, your app need to subscribe to Layer.InitializationFailed event http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Layer~Init... so you may notify your users when the server is down.


In #1, we *are* subscribed to layer.InitializationFailed, and we get no notification of errors (layer.InitializationFailed is not called in this case.) Is there any way to programatically detect this case, and then recover from it?

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
Oh you're right in case#1, the layer has already initialized when you perform zoom so you can use NetworkInterface.GetIsNetworkAvailable() to check if network connection was dropped/
0 Kudos
AndySanford
New Contributor
Oh you're right in case#1, the layer has already initialized when you perform zoom so you can use NetworkInterface.GetIsNetworkAvailable() to check if network connection was dropped/


I don't think that will work well, for at least two reasons:

a) since we don't get notified by the layer when comm errors occur after init, we wouldn't really know *when* to call GetIsNetworkAvailable().  I don't think we want to keep polling it.

b) Even if we periodically poll GetisNetworkAvailable, or instead signed up for NetworkChange.NetworkAddressChanged() and call the method when that triggers, using GetIsNetworkAvailable() is not a reliable way to tell if the layer is having comm problems.  This is because:

i) this method reports if *any* network connections are available.  We might have two network cards, and the one that gets to the server could be disconnected

ii) even with one net card, the cable between the pc and router might be plugged in, but the server may still be unreachable, and GetIsNetworkAvailable() will still report true.  In fact, the connection all the way to server could be good, and the layer could be having trouble.  Even pinging the server isn't enough.  To know if the layer is having trouble, we need the layer to tell us.  Is there a way to have the layer notify us?  Otherwise, the user will complain that the screen just turns blank and we don't report any problems, which isn't very informative.

Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
Can you check this Map.ExtentChanging or ExtentChanged?
0 Kudos