AnsweredAssumed Answered

Get nothing from the localserver service (v.100)

Question asked by pierrejeanmuller on Apr 21, 2017
Latest reply on Apr 26, 2017 by pierrejeanmuller

Hello,

 

I am trying to use the local server. The service is starting without errors, but it is not visible when added to the map.

private Esri.ArcGISRuntime.LocalServices.LocalServer _localServer;
ArcGISMapImageLayer localServiceLayer;
private async void StartLocalServer()
        {
            // Get the singleton LocalServer object using the static "Instance" property
            _localServer = Esri.ArcGISRuntime.LocalServices.LocalServer.Instance;

            //_localServer.AppDataPath = @"C:\Temp\localserver";

            // Handle the StatusChanged event to react when the server is started
            _localServer.StatusChanged += ServerStatusChanged;

            // Start the local server instance
            await _localServer.StartAsync();
        }

private void ServerStatusChanged(object sender, Esri.ArcGISRuntime.LocalServices.StatusChangedEventArgs e)
        {
            // Check if the server started successfully
            if (e.Status == Esri.ArcGISRuntime.LocalServices.LocalServerStatus.Started)
            {
                LocalMapService localmapService = new LocalMapService(@"G:\GISData\myData.mpk");

                //MessageBox.Show(localmapService.Status.ToString());
                localmapService.StatusChanged += (svc, args) =>
                {
                    //MessageBox.Show(localmapService.Status.ToString());

                    // If started successfully, add a layer from the service
                    if (args.Status == LocalServerStatus.Started)
                    {
                        // Get the service URL
                        var mapServiceUrl = (svc as LocalMapService).Url;

                        // Create a new ArcGISMapImageLayer
                        localServiceLayer = new ArcGISMapImageLayer(mapServiceUrl);


                        localServiceLayer.LoadAsync();

                        // Set layer opacity to semi-transparent
                        localServiceLayer.Opacity = 1;

                        // Add the layer to the map
                        MainMapView.Map.OperationalLayers.Add(localServiceLayer);
                    }
                };
                // Start the local map service
                localmapService.StartAsync();
            }
        }

Outcomes