Click or drag to resize

LocalServiceStartAsync Method

Asynchronously starts this local service instance, and returns a Task object.

Namespace:  Esri.ArcGISRuntime.LocalServices
Assembly:  Esri.ArcGISRuntime.LocalServices (in Esri.ArcGISRuntime.LocalServices.dll) Version: 100.9.0
public virtual Task StartAsync()

Return Value

Type: Task
A task that represents the asynchronous start operation.
InvalidOperationExceptionService can only be started when in the stopped state.
LocalServerExceptionCannot start this service as it is already running on the LocalServer.
LocalServerExceptionCannot start service because a LocalService with the same Name is already running.
LocalServerExceptionLocal Server requires a standard level license to start. The current license level is basic (see ArcGISRuntimeEnvironment.License.Level). For a deployment you can initialize the runtime with a standard level license in ArcGISRuntimeEnvironment.License.SetLicense(). If you are developing an app then you can avoid setting ArcGISRuntimeEnvironment.ClientId to remain in developer mode to try out LocalServer.


Example Name: LocalServerMapImageLayer

Start the Local Server and Local Map Service, create an ArcGIS Map Image Layer from the Local Map Service, and add it to a map.

Code example screen shot.

// Copyright 2018 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 ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.LocalServices;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.LocalServerMapImageLayer
        name: "Local Server map image layer",
        category: "Local Server",
        description: "Start the Local Server and Local Map Service, create an ArcGIS Map Image Layer from the Local Map Service, and add it to a map.",
        instructions: "The Local Server and local map service will automatically be started and, once running, a map image layer will be created and added to the map.",
        tags: new[] { "image", "layer", "local", "offline", "server" })]
    public partial class LocalServerMapImageLayer
        // Hold a reference to the local map service
        private LocalMapService _localMapService;

        public LocalServerMapImageLayer()

            // set up the sample

        private async void Initialize()
            // Create a map and add it to the view
            MyMapView.Map = new Map(Basemap.CreateLightGrayCanvasVector());

                // LocalServer must not be running when setting the data path.
                if (LocalServer.Instance.Status == LocalServerStatus.Started)
                    await LocalServer.Instance.StopAsync();

                // Set the local data path - must be done before starting. On most systems, this will be C:\EsriSamples\AppData.
                // This path should be kept short to avoid Windows path length limitations.
                string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName;
                string tempDataPath = Path.Combine(tempDataPathRoot, "EsriSamples", "AppData");
                Directory.CreateDirectory(tempDataPath); // CreateDirectory won't overwrite if it already exists.
                LocalServer.Instance.AppDataPath = tempDataPath;

                // Start the local server instance
                await LocalServer.Instance.StartAsync();

                // Get the path to the map package that will be served
                string datapath = GetDataPath();

                // Create the Map Service from the data
                _localMapService = new LocalMapService(datapath);

                // Start the feature service
                await _localMapService.StartAsync();

                // Get the url to the map service
                Uri myServiceUri = _localMapService.Url;

                // Create the layer from the url
                ArcGISMapImageLayer myImageLayer = new ArcGISMapImageLayer(myServiceUri);

                // Add the layer to the map

                // Wait for the layer to load
                await myImageLayer.LoadAsync();

                // Set the viewpoint on the map to show the data
                MyMapView.SetViewpoint(new Viewpoint(myImageLayer.FullExtent));
            catch (Exception ex)
                var localServerTypeInfo = typeof(LocalMapService).GetTypeInfo();
                var localServerVersion = FileVersionInfo.GetVersionInfo(localServerTypeInfo.Assembly.Location);

                MessageBox.Show($"Please ensure that local server {localServerVersion.FileVersion} is installed prior to using the sample. The download link is in the description. Message: {ex.Message}", "Local Server failed to start");

        private static string GetDataPath()
            return DataManager.GetDataFolder("dee5d8060a6048a4b063484199a9546b", "RelationshipID.mpk");
<UserControl x:Class="ArcGISRuntime.WPF.Samples.LocalServerMapImageLayer.LocalServerMapImageLayer"
             d:DesignHeight="300" d:DesignWidth="300">
        <esri:MapView x:Name="MyMapView"/>

See Also
Additional Examples
Hyperlink to ExampleDescription
LocalServerFeatureLayerStart a local feature service and display its features in a map.
LocalServerGeoprocessingCreate contour lines from local raster data using a local geoprocessing package `.gpk` and the contour geoprocessing tool.
LocalServerMapImageLayerStart the Local Server and Local Map Service, create an ArcGIS Map Image Layer from the Local Map Service, and add it to a map.
LocalServerServicesDemonstrates how to start and stop the Local Server and start and stop a local map, feature, and geoprocessing service running on the Local Server.