Click or drag to resize
Code Example: MapServiceInfo_DocumentInfo_LayerServiceInfo

Demonstrates getting detailed ArcGIS Server MapServer metadata to obtain MapServiceInfo data for various ArcGISDynamicMapServiceLayer and ArcGISTiledMapServiceLayer web services.

Code Example
Map Service Info Document Info Layer Service Info

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

XAML
<Window x:Class="MapServiceInfo_DocumentInfo_LayerServiceInfo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
    Title="MainWindow" Height="600" Width="800">
    <Grid x:Name="LayoutRoot">
        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Horizontal">
                <Button x:Name="Button1" Content="Get the MapServiceInfo and DocumentInfo metadata for the ArcGIS Server service." Click="Button1_Click" Width="782"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <esri:MapView x:Name="MapView1" Height="534" Width="354" >
                    <esri:Map x:Name="Map">

                        <!--
                        INSTRUCTIONS: 
                        Uncomment/comment out the various ArcGISDynamicMapServiceLayer's and ArcGISTiledMapServiceLayer's you want to interrogate the
                        metadata information for via the MapServiceInfo, DocumentInfo, and LayerServiceInfo objects.
                        -->

                        <!--<esri:ArcGISTiledMapServiceLayer ID="ESRI_StreetMap_World_2D" ServiceUri="http://server.arcgisonline.com/arcgis/rest/services/ESRI_StreetMap_World_2D/MapServer"/>-->
                        <!--<esri:ArcGISTiledMapServiceLayer ID="World_Topo_Map" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer" />-->
                        <!--<esri:ArcGISTiledMapServiceLayer ID="World_Light_Gray_Base" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer" />-->
                        <!--<esri:ArcGISTiledMapServiceLayer ID="NatGeo_World_Map" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer" />-->
                        <!--<esri:ArcGISTiledMapServiceLayer ID="Ocean_Basemap" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Ocean_Basemap/MapServer" />-->
                        <!--<esri:ArcGISTiledMapServiceLayer ID="World_Terrain_Base" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer" />-->
                        <esri:ArcGISTiledMapServiceLayer ID="World_Street_Map" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />

                        <!--<esri:ArcGISDynamicMapServiceLayer ID="World_Light_Gray_Base" ImageFormat="PNG24" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"/>-->
                        <!--<esri:ArcGISDynamicMapServiceLayer ID="World Time Zones" ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer"/>-->
                        <!--<esri:ArcGISDynamicMapServiceLayer ID="BloomfieldHillsMichigan" ServiceUri="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/Parcels/MapServer"/>-->
                        <!--<esri:ArcGISDynamicMapServiceLayer ID="ESRI_StateCityHighway_USA" ServiceUri="http://sampleserver1.arcgisonline.com/arcgis/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>-->
                        <esri:ArcGISDynamicMapServiceLayer ID="USA_Unemployment_Rate" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Demographics/USA_Unemployment_Rate/MapServer"/>
                        <!--<esri:ArcGISDynamicMapServiceLayer ID="USA" ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" />-->
                        <!--<esri:ArcGISDynamicMapServiceLayer ID="KSPetro" ServiceUri="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer"/>-->

                    </esri:Map>
                </esri:MapView>
                <TextBox x:Name="TextBlock1" TextWrapping="Wrap" Width="434" Height="534" />
            </StackPanel>
        </StackPanel>
    </Grid>
</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "MapServiceInfo_DocumentInfo_LayerServiceInfo.MainWindow" to be just "MainWindow".

namespace MapServiceInfo_DocumentInfo_LayerServiceInfo
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // Get the collection of layers in the MapView.
            Esri.ArcGISRuntime.Layers.LayerCollection myLayers = MapView1.Map.Layers;

            // Create a StringBuilder to hold information to display back to the user.
            System.Text.StringBuilder myStringBuilder_MapServiceInfo = new System.Text.StringBuilder();

            // Loop through each layer.
            foreach (Esri.ArcGISRuntime.Layers.Layer onelayer in myLayers)
            {
                // Create a MapServiceInfo object to get metadata about the MapServer.
                Esri.ArcGISRuntime.ArcGISServices.MapServiceInfo myMapServiceInfo = null;

                // Test if the MapServer is an ArcGISDynamicMapServiceLayer.
                if (onelayer is Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer)
                {
                    // Get the ArcGISDynamicMapServiceLayer from the Map.
                    Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer myArcGISDynamicMapServiceLayer = (Esri.ArcGISRuntime.Layers.ArcGISDynamicMapServiceLayer)onelayer;

                    // Get the MapServiceInfo object.
                    myMapServiceInfo = myArcGISDynamicMapServiceLayer.ServiceInfo;
                }

                // Test if the MapServer is an ArcGISTiledMapServiceLayer.
                if (onelayer is Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer)
                {
                    // Get the ArcGISTiledMapServiceLayer from the Map.
                    Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer myArcGISTiledMapServiceLayer = (Esri.ArcGISRuntime.Layers.ArcGISTiledMapServiceLayer)onelayer;

                    // Get the MapServiceInfo object.
                    myMapServiceInfo = myArcGISTiledMapServiceLayer.ServiceInfo;
                }

                // Display the detailed metadata about the layer via the MapServiceInfo object.
                GetMetadata2(myMapServiceInfo, myStringBuilder_MapServiceInfo);
            }

            // Display all of the metadata information back to the user.
            TextBlock1.Text = myStringBuilder_MapServiceInfo.ToString();
        }

        public System.Text.StringBuilder GetMetadata2(Esri.ArcGISRuntime.ArcGISServices.MapServiceInfo myMapServiceInfo, System.Text.StringBuilder myStringBuilder_MapServiceInfo)
        {
            // MapServiceInfo.MapName
            myStringBuilder_MapServiceInfo.AppendLine("MapName: " + myMapServiceInfo.MapName.ToString());

            // MapServiceInfo.Capabilities
            if (myMapServiceInfo.Capabilities != null)
            {
                System.Collections.Generic.IReadOnlyList<string> myCapabilities_IReadOnlyList = myMapServiceInfo.Capabilities;
                string myCapabilities_String = "";
                foreach (string oneCapability in myCapabilities_IReadOnlyList)
                {
                    myCapabilities_String = myCapabilities_String + oneCapability.ToString() + " ";
                }
                myStringBuilder_MapServiceInfo.AppendLine("Capabilities: " + myCapabilities_IReadOnlyList.Count.ToString() + " " + myCapabilities_String);
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("Capabilities: [Nothing/null]");
            }

            // MapServiceInfo.CopyrightText
            if (myMapServiceInfo.CopyrightText != null)
            {
                myStringBuilder_MapServiceInfo.AppendLine("CopyrightText: " + myMapServiceInfo.CopyrightText.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("CopyrightText: [Nothing/null]");
            }

            // MapServiceInfo.CurrentVersion
            myStringBuilder_MapServiceInfo.AppendLine("CurrentVersion: " + myMapServiceInfo.CurrentVersion.ToString());

            // MapServiceInfo.Description
            if (myMapServiceInfo.Description != null)
            {
                myStringBuilder_MapServiceInfo.AppendLine("Description: " + myMapServiceInfo.Description.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("Description: [Nothing/null]");
            }

            // MapServiceInfo.DocumentInfo
            if (myMapServiceInfo.DocumentInfo != null)
            {
                Esri.ArcGISRuntime.ArcGISServices.DocumentInfo myDocumentInfo = myMapServiceInfo.DocumentInfo;
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo: [DETAILS]");
                if (myDocumentInfo.AntialiasingMode != null)
                {
                    myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.AntialiasingMode: " + myDocumentInfo.AntialiasingMode.ToString());
                }
                else
                {
                    myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.AntialiasingMode: [Nothing/null]");
                }
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.Author: " + myDocumentInfo.Author.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.Category: " + myDocumentInfo.Category.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.Comments: " + myDocumentInfo.Comments.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.Keywords: " + myDocumentInfo.Keywords.ToString());
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.Subject: " + myDocumentInfo.Subject.ToString());
                if (myDocumentInfo.TextAntialiasingMode != null)
                {
                    myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.TextAntialiasingMode: " + myDocumentInfo.TextAntialiasingMode.ToString());
                }
                else
                {
                    myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.TextAntialiasingMode: [Nothing/null]");
                }
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo.Title: " + myDocumentInfo.Title.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("DocumentInfo: [Nothing/null]");
            }

            // MapServiceInfo.ExportTilesAllowed
            myStringBuilder_MapServiceInfo.AppendLine("ExportTilesAllowed: " + myMapServiceInfo.ExportTilesAllowed.ToString());

            // MapServiceInfo.FullExtent
            if (myMapServiceInfo.FullExtent != null)
            {
                // TODO: The Envelope object has many Properties. Add you own code to interrogate further.
                Esri.ArcGISRuntime.Geometry.Envelope myFullExtent = myMapServiceInfo.FullExtent;
                myStringBuilder_MapServiceInfo.AppendLine("FullExtent: " + myFullExtent.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("FullExtent: [Nothing/null]");
            }

            // MapServiceInfo.InitialExtent
            if (myMapServiceInfo.InitialExtent != null)
            {
                // TODO: The Envelope object has many Properties. Add you own code to interrogate further.
                Esri.ArcGISRuntime.Geometry.Envelope myInitialExtent = myMapServiceInfo.InitialExtent;
                myStringBuilder_MapServiceInfo.AppendLine("InitialExtent: " + myInitialExtent.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("InitialExtent: [Nothing/null]");
            }

            // MapServiceInfo.Layers (aka. LayerServiceInfo)
            if (myMapServiceInfo.Layers != null)
            {
                System.Collections.Generic.IReadOnlyList<Esri.ArcGISRuntime.ArcGISServices.LayerServiceInfo> myLayerServiceInfo_IReadOnlyList = myMapServiceInfo.Layers;
                myStringBuilder_MapServiceInfo.AppendLine("Layers: [COUNT/DETAILS] " + myLayerServiceInfo_IReadOnlyList.Count.ToString());
                foreach (Esri.ArcGISRuntime.ArcGISServices.LayerServiceInfo oneLayerServiceInfo in myLayerServiceInfo_IReadOnlyList)
                {
                    myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo.DefaultVisibility: " + oneLayerServiceInfo.DefaultVisibility.ToString());
                    myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo.ID: " + oneLayerServiceInfo.ID.ToString());
                    myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo.MaxScale: " + oneLayerServiceInfo.MaxScale.ToString());
                    myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo.MinScale: " + oneLayerServiceInfo.MinScale.ToString());
                    myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo.Name: " + oneLayerServiceInfo.Name.ToString());
                    if (oneLayerServiceInfo.SubLayerIds != null)
                    {
                        myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo.SubLayerIds: " + oneLayerServiceInfo.SubLayerIds.ToString());
                    }
                    else
                    {
                        myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo.SubLayerIds: [Nothing/null]");
                    }
                }
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("LayerServiceInfo: [Nothing/null]");
            }

            // MapServiceInfo.MaxImageHeight
            myStringBuilder_MapServiceInfo.AppendLine("MaxImageHeight: " + myMapServiceInfo.MaxImageHeight.ToString());

            // MapServiceInfo.MaxImageWidth
            myStringBuilder_MapServiceInfo.AppendLine("MaxImageWidth: " + myMapServiceInfo.MaxImageWidth.ToString());

            // MapServiceInfo.MaxRecordCount
            myStringBuilder_MapServiceInfo.AppendLine("MaxRecordCount: " + myMapServiceInfo.MaxRecordCount.ToString());

            // MapServiceInfo.MaxScale
            myStringBuilder_MapServiceInfo.AppendLine("MaxScale: " + myMapServiceInfo.MaxScale.ToString());

            // MapServiceInfo.MinScale
            myStringBuilder_MapServiceInfo.AppendLine("MinScale: " + myMapServiceInfo.MinScale.ToString());

            // MapServiceInfo.ServiceDescription
            myStringBuilder_MapServiceInfo.AppendLine("ServiceDescription: " + myMapServiceInfo.ServiceDescription.ToString());

            // MapServiceInfo.SpatialReference
            if (myMapServiceInfo.SpatialReference != null)
            {
                // TODO: The SpatialReference object has many Properties. Add you own code to interrogate further.
                Esri.ArcGISRuntime.Geometry.SpatialReference mySpatialReference = myMapServiceInfo.SpatialReference;
                myStringBuilder_MapServiceInfo.AppendLine("SpatialReference: " + mySpatialReference.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("SpatialReference: [Nothing/null]");
            }

            // MapServiceInfo.SupportedImageFormatTypes
            if (myMapServiceInfo.SupportedImageFormatTypes != null)
            {
                System.Collections.Generic.IReadOnlyList<Esri.ArcGISRuntime.ArcGISServices.ImageFormat> mySupportedImageFormatTypes_IReadOnlyList = myMapServiceInfo.SupportedImageFormatTypes;
                string mySupportedImageFormatTypes_String = "";
                foreach (Esri.ArcGISRuntime.ArcGISServices.ImageFormat oneImageFormat in mySupportedImageFormatTypes_IReadOnlyList)
                {
                    mySupportedImageFormatTypes_String = mySupportedImageFormatTypes_String + oneImageFormat.ToString() + " ";
                }
                myStringBuilder_MapServiceInfo.AppendLine("SupportedImageFormatTypes: " + mySupportedImageFormatTypes_IReadOnlyList.Count.ToString() + " " + mySupportedImageFormatTypes_String);
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("SupportedImageFormatTypes: [Nothing/null]");
            }

            // MapServiceInfo.SupportsDynamicLayers
            myStringBuilder_MapServiceInfo.AppendLine("SupportsDynamicLayers: " + myMapServiceInfo.SupportsDynamicLayers.ToString());

            // MapServiceInfo.Tables
            if (myMapServiceInfo.Tables != null)
            {
                System.Collections.Generic.IReadOnlyList<Esri.ArcGISRuntime.ArcGISServices.Table> myTables_IReadOnlyList = myMapServiceInfo.Tables;
                string myTables_String = "";
                foreach (Esri.ArcGISRuntime.ArcGISServices.Table oneTable in myTables_IReadOnlyList)
                {
                    myTables_String = myTables_String + oneTable.Name.ToString() + "(" + oneTable.Name.ToString() + ") ";
                }
                myStringBuilder_MapServiceInfo.AppendLine("Tables: " + myTables_IReadOnlyList.Count.ToString() + " " + myTables_String);
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("Tables: [Nothing/null]");
            }

            // MapServiceInfo.TileInfo
            if (myMapServiceInfo.TileInfo != null)
            {
                // TODO: The TileInfo object has many Properties. Add you own code to interrogate further.
                Esri.ArcGISRuntime.ArcGISServices.TileInfo myTileInfo = myMapServiceInfo.TileInfo;
                myStringBuilder_MapServiceInfo.AppendLine("TileInfo: " + myTileInfo.Format.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("TileInfo: [Nothing/null]");
            }

            // MapServiceInfo.TileServers
            if (myMapServiceInfo.TileServers != null)
            {
                System.Collections.Generic.IReadOnlyList<string> myTileServers_IReadOnlyList = myMapServiceInfo.TileServers;
                string myTileServers_String = "";
                foreach (string oneTileServer in myTileServers_IReadOnlyList)
                {
                    myTileServers_String = myTileServers_String + oneTileServer.ToString() + " ";
                }
                myStringBuilder_MapServiceInfo.AppendLine("TileServers: " + myTileServers_IReadOnlyList.Count.ToString() + " " + myTileServers_String);
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("TileServers: [Nothing/null]");
            }

            // MapServiceInfo.TimeInfo
            if (myMapServiceInfo.TimeInfo != null)
            {
                // TODO: The TimeInfo object has many Properties. Add you own code to interrogate further.
                Esri.ArcGISRuntime.ArcGISServices.TimeInfo myTimeInfo = myMapServiceInfo.TimeInfo;
                myStringBuilder_MapServiceInfo.AppendLine("TimeInfo: " + myTimeInfo.TimeExtent.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("TimeInfo: [Nothing/null]");
            }

            // MapServiceInfo.Units
            if (myMapServiceInfo.Units != null)
            {
                myStringBuilder_MapServiceInfo.AppendLine("Units: " + myMapServiceInfo.Units.ToString());
            }
            else
            {
                myStringBuilder_MapServiceInfo.AppendLine("Units: [Nothing/null]");
            }

            // Add some formatting if there are multiple layers/tables in the FeatureServiceLayerInfo object.
            myStringBuilder_MapServiceInfo.AppendLine("");
            myStringBuilder_MapServiceInfo.AppendLine("****************************************************************");
            myStringBuilder_MapServiceInfo.AppendLine("");

            // Return the StringBuilder. 
            return myStringBuilder_MapServiceInfo;
        }
    }
}