Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

WMS service catalog

This code sample is available for these platforms:
View Sample on GitHub

Connect to a WMS service and show the available layers and sublayers.

Image of WMS service catalog

Use case

WMS services often contain many layers and sublayers. Presenting the layers and sublayers in a UI allows you to explore what is available in the service and add individual layers to a map.

How to use the sample

  1. Open the sample. A hierarchical list of layers and sublayers will appear.
  2. Select a layer to enable it for display. If the layer has any children, the children will also be selected.

How it works

  1. A WmsService is created and loaded.
  2. WmsService has a ServiceInfo property, which is a WmsServiceInfo. WmsServiceInfo has a WmsLayerInfo object for each layer (excluding sublayers) in the LayerInfos collection.
  3. A method is called to recursively discover sublayers for each layer. Layers are wrapped in a view model and added to a list.
    • The view model has a Select method which recursively selects or deselects itself and sublayers.
    • The view model tracks the children and parent of each layer.
  4. Once the layer selection has been updated, another method is called to create a new WmsLayer from a list of selected WmsLayerInfo.

Relevant API

  • WmsLayer(List)
  • WmsLayerInfo
  • WmsService
  • WmsServiceInfo

About the data

This sample shows forecasts guidance warnings from an ArcGIS REST service produced by the U.S. National Weather Service. The map shows fronts, highs, and lows, as well as areas of forecast precipitation.


catalog, OGC, web map service, WMS

Sample Code

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

<ContentPage xmlns=""
            <RowDefinition Height="auto" />
            <RowDefinition Height="150" />
            <RowDefinition Height="*" />
        <Label Text="Select a WMS layer from the list for display:" Grid.Row="0" />
        <ListView x:Name="MyDisplayList" Grid.Row="1" ItemSelected="MyDisplayList_SelectionChanged">
                    <TextCell Text="{Binding Name}" />
        <esriUI:MapView x:Name="MyMapView" Grid.Row="2" />
// Copyright 2017 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Ogc;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms;

namespace ArcGISRuntime.Samples.WmsServiceCatalog
        name: "WMS service catalog",
        category: "Layers",
        description: "Connect to a WMS service and show the available layers and sublayers. ",
        instructions: "",
        tags: new[] { "OGC", "WMS", "catalog", "web map service" })]
    public partial class WmsServiceCatalog : ContentPage
        // Hold the URL to the WMS service providing the US NOAA National Weather Service forecast weather chart
        private readonly Uri _wmsUrl = new Uri(

        // Hold a list of LayerDisplayVM; this is the ViewModel
        private readonly ObservableCollection<LayerDisplayVM> _viewModelList = new ObservableCollection<LayerDisplayVM>();

        public WmsServiceCatalog()

            // Initialize the map

        private async void Initialize()
            // Apply an imagery basemap to the map.
            MyMapView.Map = new Map(Basemap.CreateDarkGrayCanvasVector());

            // Create the WMS Service.
            WmsService service = new WmsService(_wmsUrl);

                // Load the WMS Service.
                await service.LoadAsync();

                // Get the service info (metadata) from the service.
                WmsServiceInfo info = service.ServiceInfo;

                // Get the list of layer infos.
                foreach (var layerInfo in info.LayerInfos)
                    LayerDisplayVM.BuildLayerInfoList(new LayerDisplayVM(layerInfo, null), _viewModelList);

                // Update the map display based on the viewModel.

                // Update the list of layers.
                MyDisplayList.ItemsSource = _viewModelList;
            catch (Exception e)
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");

        /// <summary>
        /// Updates the map with the latest layer selection.
        /// </summary>
        private async void UpdateMapDisplay(ObservableCollection<LayerDisplayVM> displayList)
            // Remove all existing layers.

            // Get a list of selected LayerInfos.
            List<WmsLayerInfo> selectedLayers = displayList.Where(vm => vm.IsEnabled).Select(vm => vm.Info).ToList();

            // Return if no layers selected.
            if (!selectedLayers.Any())

            // Create a new WmsLayer from the selected layers.
            WmsLayer myLayer = new WmsLayer(selectedLayers);

                // Load the layer.
                await myLayer.LoadAsync();

                // Add the layer to the map.

                // Update the viewpoint.
                await MyMapView.SetViewpointAsync(new Viewpoint(myLayer.FullExtent));
            catch (Exception e)
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");

        /// <summary>
        /// Takes action once a new layer selection is made.
        /// </summary>
        private void MyDisplayList_SelectionChanged(object sender, SelectedItemChangedEventArgs e)
            // Deselect all layers.
            foreach (LayerDisplayVM item in _viewModelList)

            // Hold a reference to the selected item
            LayerDisplayVM selectedItem = (LayerDisplayVM) e.SelectedItem;

            // Update the selection

            // Update the map

    /// <summary>
    /// This is a ViewModel class for maintaining the state of a layer selection.
    /// Typically, this would go in a separate file, but it is included here for clarity.
    /// </summary>
    public class LayerDisplayVM
        public WmsLayerInfo Info { get; }

        // True if layer is selected for display.
        public bool IsEnabled { get; private set; }

        // Keeps track of how much indentation should be added (to simulate a tree view in a list).
        private int NestLevel
                if (Parent == null)
                    return 0;

                return Parent.NestLevel + 1;

        private List<LayerDisplayVM> Children { get; set; }

        private LayerDisplayVM Parent { get; }

        public LayerDisplayVM(WmsLayerInfo info, LayerDisplayVM parent)
            Info = info;
            Parent = parent;

        // Select this layer and all child layers.
        public void Select(bool isSelected = true)
            IsEnabled = isSelected;
            if (Children == null)

            foreach (var child in Children)

        public string Name => $"{new String(' ', NestLevel * 8)} {Info.Title}";

        public static void BuildLayerInfoList(LayerDisplayVM root, IList<LayerDisplayVM> result)
            // Add the root node to the result list.

            // Initialize the child collection for the root.
            root.Children = new List<LayerDisplayVM>();

            // Recursively add sublayers.
            foreach (WmsLayerInfo layer in root.Info.LayerInfos)
                // Create the view model for the sublayer.
                LayerDisplayVM layerVM = new LayerDisplayVM(layer, root);

                // Add the sublayer to the root's sublayer collection.

                // Recursively add children.
                BuildLayerInfoList(layerVM, result);