Select to view content in your preferred language

Legend with secure services

1477
9
02-23-2011 06:58 AM
JasonKnisley
Deactivated User
I'm experiencing an interesting issue with using secure services in the Legend control (based on the sample at http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LegendWithTemplates)

If add the individual feature layers of a map service to the map, their legend icons are appropriately displayed in the Legend control.  However, if I attempt to add the service as an ArcGISDynamicMapServiceLayer, none of the legend icons will appear in the legend.

To illustrate, I have attached a screenshot that contains a secure service as a ArcGISDynamicMapServiceLayer first, and then some individual feature layers of that service afterwards.

I have experienced this problem with every secure service that I have tried so far.  With non-secure services everything loads appropriately whether they are of type ArcGISDynamicMapServiceLayer or FeatureLayer.

Any thoughts on how to get the Legend control to display the legend icons of an ArcGISDynamicMapServiceLayer instead of having to create a slew of FeatureLayers?
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
I don't see any issue with the attached screenshot of legend control. If you look at the SDK sample, "United States" legend looks similar, this is also an ArcGISDynamicMapServiceLayer.
0 Kudos
JasonKnisley
Deactivated User
The issue with the screen shot is that under the Basemap service, none of the layers are showing legend icons.  I uploaded another screen shot illustrating the differences between the unsecured service ("United States") and the secured service ("Basemap").

I have replicated this same problem using QueryLegendInfos().  If I use that with an unsecure ArcGISDynamicMapServiceLayer or with a FeatureLayer (whether secure or not) I am able to obtain legend icons, but if I use it with a secure ArcGISDynamicMapServiceLayer, there are no legend icons returned.  LegendItemInfos is always null.

My callback function (admittedly not pretty, but I wrote it quickly for testing purposes) is below.
private void callback(LayerLegendInfo layerLegendInfo, TreeViewItem treeViewItem)
        {
            // group/parent layer
            if (layerLegendInfo.LayerLegendInfos != null)
            {
                TreeViewItem tviGroup = new TreeViewItem() { Header = layerLegendInfo.LayerName };

                if (treeViewItem == null)
                {
                    treeViewItem = tviGroup;
                    stackPanelTest.Children.Add(treeViewItem);
                }
                else
                {
                    treeViewItem.Items.Add(tviGroup);
                }

                foreach (LayerLegendInfo info in layerLegendInfo.LayerLegendInfos)
                    callback(info, tviGroup);
            }
            // feature layer with legend icons
            else if (layerLegendInfo.LegendItemInfos != null)
                foreach (LegendItemInfo info in layerLegendInfo.LegendItemInfos)
                {
                    StackPanel stackPanelImage = new StackPanel() { Orientation = Orientation.Horizontal };
                    stackPanelImage.Children.Add(new TextBlock() { Text = "2-"+layerLegendInfo.LayerName, Margin = new Thickness(5) });
                    stackPanelImage.Children.Add(new Image() { Source = info.ImageSource });
                    treeViewItem.Items.Add(stackPanelImage);
                }
            // feature layer with no legend icons returned
            else
            {
                StackPanel stackPanelImage = new StackPanel() { Orientation = Orientation.Horizontal };
                stackPanelImage.Children.Add(new TextBlock() { Text = "3-"+layerLegendInfo.LayerName, Margin = new Thickness(5) });
                treeViewItem.Items.Add(stackPanelImage);
            }
        }
0 Kudos
DominiqueBroux
Esri Frequent Contributor
What is the version of your ArcGIS server?
Is it 10SP1 (10.01) or a previous version?
That's important to know because in one case the legend infos are coming from your arcgis server, in the other case from arcgis.com.
0 Kudos
JenniferNery
Esri Regular Contributor
I cannot replicate the issue with a secured 10 SP1 service. Are you using Silverlight or WPF? If you are using WPF, you need to supply Credentials property to your ArcGISDynamicMapServiceLayer.
0 Kudos
JasonKnisley
Deactivated User
We don't have 10SP1 installed yet.  Just Server 10.0.0.0.

I am using Silverlight, and have tried setting the ProxyURL property of ArcGISDynamicMapServiceLayer and also I have done it without, which then prompts me for a username and password when the application loads.  In either case the result is the same; my code above using QueryLegendInfos() does not return legend images, and neither does the Legend control from ESRI.ArcGIS.Client.Toolkit.  The rest of the service loads fine, and both my code and the Legend control will return the layer names but not the legend images.  This is true for all 8 secure services I've tested so far which are hosted on Server 10.0.0.0.  If we remove security the images load fine, but we need to have security enabled.

Oddly enough (and I know I'm repeating myself from a previous post), if I add all of the individual layers from the service to the map as FeatureLayers then the legend icons can be retrieved both from my code above and from the Legend control.  Obviously, however, this is tedious and impractical to have to avoid using ArcGISDynamicMapServiceLayers.

If you would like to test this with the services that I am using, I would be happy to create a temporary account on the server for this purpose.  If this would help, please contact me at jknisley@memphis.edu for the service URLs and authentication info.
0 Kudos
JenniferNery
Esri Regular Contributor
Just to clarify, are you able to see the features on your map when you use ArcGISDynamicMapServiceLayer using secured service and supplying the proper credentials? On your server, do you have Anonymous Authentication Disabled and either Basic Authentication or Windows Authentication Enabled? I just wanted to know if the failure is in the authentication or if we missed something in the Legend control.
0 Kudos
JasonKnisley
Deactivated User
The services do all appear on the map appropriately.  I can perform query tasks and identify tasks and can use sliders/checkboxes to adjust opacity/visibility.  It's simply the legend icons from the Legend control and from QueryLegendInfos() that fail to appear (again, only a problem with ArcGISDynamicMapServiceLayer and not with FeatureLayer types).

Edit:
Anonymous Authentication is disabled and Basic Authentication is enabled.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
After further verifications, it looks like the arcgis.com legend service doesn't support secure services.

But this should work with arcgis server from version 10SP1 (because in this case the arcgis.com fallback mechanism is no longer used).

Is there any chance you can upgrade your server?
0 Kudos
JasonKnisley
Deactivated User
Yes, we will be upgrading our server to 10SP1 within the next couple of weeks.  It's good to know that will solve the problem.  Thank you.

Out of sheer curiosity (and because we sometimes work with clients who still have older versions of ArcGIS Server), do you know if they are any plans for the arcgis.com legend service to support secure services in the future, or is that not a priority since it's a non-issue with the current version of ArcGIS Server?
0 Kudos