Troubleshooting blank layers

On August 24, 2009, in Web, by rexhansen

The Silverlight API is a client application dependent on services that might fail or be unavailable. In general, the Map control will not throw an exception if one service fails. This means that if one service is down, the application will continue to run and access the remaining layers. However, it also means that you don’t automatically get any error reporting, and if all your services fail, you will just end up with a blank map.


When looking at the ESRI Silverlight forums, several users have reported issues with getting their layers to display or encountering blank maps. This blog post tries to outline the common reasons why a service does not display in the map, and how to remedy it.


Most of the problems with a missing layer are related to browser security issues, so to trouble shoot client applications, there is one tool that I will recommend anyone to get familiar with: Fiddler. This is a free HTTP tracing tool that tracks the requests and responses between the browser and the web server, and logs if any requests failed. You can download this tool from http://www.fiddler2.com/.


Once installed and launched, any network traffic initiated by Internet Explorer will be tracked by Fiddler. Note that any traffic to http://localhost/ is not tracked by default, and requires extra configuration. Other browsers might also require explicit configuration to work with Fiddler. I will be using Fiddler several times in this blogpost to track down issues you may experience.


Cross-domain limitations

Let’s for sake of argument say you installed ArcGIS Server on your own server, and you are trying to use one of its services. You first navigate to a service at your REST endpoint and copy/paste the URL to a layer in your Silverlight application, but the layer never shows. Let’s see what happens in Fiddler:





We see two requests. Both are highlighted in red, meaning an error occurred, and from the result code “404″ we can see that none of these files were found. So what are these files it tries to get from the root of my map server?


Silverlight does not allow you to make requests to servers hosted on a different host than your web application. In this case I was running my application on http://localhost/, and trying to access a service on http://myserver/.  Silverlight will first verify that the server allows other applications to perform requests against that server. It does this by trying to download a clientaccesspolicy.xml file from the domain. This is a Silverlight access configuration file telling the client who can call the server and which parts it can request. Flex has a similar pattern in place using a crossdomain.xml file. If it fails to find the clientaccesspolicy.xml file, Silverlight will try and search for Flex’s crossdomain.xml file and use that instead. If both fail, services on the server will be unavailable, the layer will not be able to initialize itself, and it will not render in the map. You can read more about this Silverlight security feature here, and you can look at the policy file that ArcGIS Online uses here.  If your services and application are hosted on the same domain AND port number, this should not be an issue. It’s worth noting the port constraint, since Visual Studio by default will run the autogenerated test-website on a different port on localhost than your ArcGIS REST services (not to mention that you shouldn’t be using localhost in the Url for layer since ‘localhost’ would mean something different to each client hitting your Silverlight application).


The cross domain restriction is by far the number one reason for a service failing to load.


Cross-scheme access

Another security feature in Silverlight is one preventing you from requesting data across different schemes, like http:// https:// and file://.  If you try to run a Silverlight application with a Map control using file:// in your browser URL, you might see this in your Map control:


 


This is because the Map control will need to be in an application hosted on a http or https website, but you are running the application from the file system (scheme).  To resolve this, make sure your Silverlight application hosted by a Web server and make sure the Web site is set as the startup project in Visual Studio. When you start a new Silverlight application project in Visual Studio, make sure you say yes to create a Web site to host your application in:




Restrictions also apply to http and https schemes. If your application is hosted on https and your service is hosted on http, or visa versa, you can access the service if explicitly permitted by the clientaccesspolicy.xml.  You cannot access images across schemes though, so while a request for service metadata may succeed, the request for a dynamic map image or cache tile will fail.   An upcoming blog post will cover this scenario in more detail. 


Hopefully at this point you’re able to see your map, and Fiddler will show something like:



In sequence you will see one successful request for clientaccesspolicy.xml, then a request for the service metadata, next a request for an image url, and lastly for the actual map image that was generated. Depending on which service type you are using, the last two requests may be different. The above example is using a dynamic map service.

Service output folder configuration

If you still have problems displaying the map service and you see something like below in Fiddler, you might have a configuration issue on your server end:



Notice how it requests images from “myserver”, but in the end tries to request an image from “localhost” (or some other domain/website unknown to the Silverlight client). If this is the case, the output folder of your ArcGIS Server service is not set up correctly.  Use Manager or Catalog to define the appropriate url to the output folder


Unsupported file format (GIF)

Silverlight does not support the GIF image format. If you are using a tiled service that has the tiles cached as GIF, it will not work with the ArcGIS Silverlight API.

Tiled layers – Wrong spatial reference

ArcGISTiledMapServiceLayer does not support re-projecting on the fly. This means that if you try and mix cached layers of different spatial reference, one or more services will not display. The first layer in the ESRI Map Control that has a spatial reference set will define the spatial reference for the entire map*, and any cached layer not matching this spatial reference will not load. You will see a request for the service metadata in Fiddler, but no requests for any image tiles. 

*Note that you can override the default map projection by explicitly setting a startup extent with a spatial reference set. See the sample in the Interactive SDK. 

Handling service errors

In the beginning I mentioned that some servers might be unavailable, and the Map control will continue to run with the remaining layers. If this is the case, you may want to let the user know that there was a problem loading a layer.  All layers have an “InitializationFailed” event you can subscribe to, that will fire in the event of a layer failing to initialize. You can also use this yourself to track down any initialization issues as well.
To listen for it, add the highlighted code to your layer definition:

<esri:ArcGISDynamicMapServiceLayer
 ID=”StreetMap”
 InitializationFailed=”layer_InitializationFailed”
 Url=”http://myserver/ArcGIS/rest/services/StreetMapUSA/MapServer” />

In the event handler you can check the InitializationFailure exception to determine what the problem was, and display a message to the user. Example:

private void layer_InitializationFailed(object sender, EventArgs e)
{
  Layer layer = sender as Layer;
  MessageBox.Show(string.Format(“Layer ‘{0}’ is currently unavailable. Error: {1}”,
     layer.ID, layer.InitializationFailure.Message));
}

Morten Nielsen
Senior Software Engineer
ArcGIS Server.NET, Silverlight/WPF, MapIt

Tagged with:  

9 Responses to Troubleshooting blank layers

  1. emelineR says:

    Brilliant! This is a great compilation of these various issues… Thanks for a great post!

  2. mpetre says:

    Morten,

    I realize this may be better suited for the forums or a trouble ticket, but I was curious if you had ran into the problem. I have a SilverLight map with a tiled ArcGIS online layer and two dynamic layers of my own with the polygon (leases) layer being defined second in the xaml. When I programatically zoom to an extent (using a query of the layers service), it zooms in and looks fine initially and then the symbology for the polygon (lease) layer disappears. As soon as I pan or zoom the map the layer reappears and continues to work as expected. Is this a known bug or am I possibly missing something in my code?

  3. mreines38 says:

    Morton, I have the same issue with publishing a Silverlight map – IE no layers displaying. I am hosting on JBoss and ‘testing out’ the technology for consideraton. From Fiddler, I can see the client policy file from arcgis get verified just fine, but I see no requests being sent for layers. I am running the sample map application as is right out of the box. Are there any other common ‘gotchas’ when hosting the map for silverlight that I am missing here? Any suggestions would be appreicated!

  4. SharpGIS says:

    mreines38: If you see a successful request for the clientaccesspolicy.xml file but no subsequent query request for the service, the CAP file is probably too limiting and preventing Silverlight from accessing the server endpoint.

  5. sqwang says:

    Could you please be more specific on “the CAP file is probably too limiting….” I am facing the same problem. Thanks a lot.

  6. rexhansen says:

    sqwang-

    CAP is short for client access policy file. Try using the file used by ArcGIS Online and see if that changes the behavior of your application: http://services.arcgisonline.com/clientaccesspolicy.xml

    Also keep in mind that cross-zone (internet security zones) or cross-scheme (http, https) requests may be causing this problem.

  7. sundar2k201 says:

    Hi,

    I have Silverlight web application hosted in SSL(https) environment. I am using cached and dynamic map servivices which are hosted in http scheme. Added client accesspolicy as given below

    < ?xml version="1.0" encoding="utf-8" ?>
    -
    -
    - -



    -


    But it displays only blank map only. and cached service writing in temp internet files folder only json output.
    please clarify whether i have to host both services in https or any other workaround available.

    Thanks
    Shanmuga

  8. stevel says:

    I was tearing my hair out over this – thanks very much for posting the solution. Steve

  9. AMIT says:

    still not able to view map on my webpage.
    I think the problem is regarding .xaml.cs page
    It is showing an erro under IniatlizedComponent i.e

    namespace SilverlightApplication17
    {
    public partial class MainPage : UserControl
    {
    public MainPage()
    {
    //InitializeComponent();// by commenting it, the program is running with no errors, but MAP is not visible
    }

    }

    }

Leave a Reply