[GIS] Loading legend of MapServer in ArcGIS Server with ArcGIS API for Silverlight

arcgis-9.3arcgis-serverarcgis-silverlight-apilegend

I have published a mapserver on my ArcGIS Server 9.3. I am developing a silverlight application using ArcGIS Silverlight API. Now I can load my map into my application and also the list of my layers that I can toggle their visibility.
I just want to load my map legend in order to know the legend of each layer. The solution which I find in arcgis silverlight example is just as follow:

<esri:Legend Map="{Binding ElementName=Map}" 
    LayerIDs="BaseLayer"
    LayerItemsMode="Tree"
    />

In visual studio 2010, I have an error for LayerIDs part which says that "Unable to cast from….". The definition of my map is also:

<esri:Map x:Name="Map"  Background="White" MouseClick="QueryPoint_MouseClick" IsLogoVisible="False">
    <esri:OpenStreetMapLayer ID="OpenStreetMap" Style="Mapnik">
    </esri:OpenStreetMapLayer>

    <esri:ArcGISDynamicMapServiceLayer ID="BaseLayer"   
            Url="http://sina-pc/ArcGIS/rest/services/Test/MapServer"
    Initialized="ArcGISDynamicMapServiceLayer_Initialized" />            
</esri:Map>

It also doesn't show any of my legends for BaseLayer map. Am I missing something or is there any problem with my map?

Best Answer

Crazy, but nevertheless... I was using AGS 10 sp1 and could not get a legend to show up from an internal test server (it could not connect to internet). For AGS below 10 sp2, AGS must be able to connect to ESRI servers to generate a legend. Upgrading to sp2 solved the problem because the legends are created on your own server. So crazy and unexpected...

From jsapi (but would apply to all) --

"If the layers are version 10 or lower the legend is created using the ArcGIS.com legend service. In order to use the ArcGIS.com legend service your map service needs to be publicly accessible and your application must be able to access ArcGIS.com."

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm

Related Question