Obtaining layer information from a LocalFeatureService

3082
4
Jump to solution
10-06-2014 02:58 PM
LukePatterson
New Contributor III

Hi,

I have a LocalFeatureService that I have created with the path to my mpk. I would like to gather the layer names for each layer from the service. When I was working with the WPF SDK there is a FeatureLayers property that returns a collection of LayerDetails (ArcGIS Runtime SDK for Microsoft WPF - Library Reference ). How can I gather this information with the SDK for .Net?

Thanks,

Luke

0 Kudos
1 Solution

Accepted Solutions
LukePatterson
New Contributor III

I actually got this figured out. For anyone else looking for the same thing...the code sample below will get the FeatureServiceInfo which has a Layers property that returns the LayerServiceInfo.

var featureService = new LocalFeatureService(mpkPathText.Text);

await featureService.StartAsync();

  if (featureService.Status == LocalServiceStatus.Running)

  {

        var layersUrl = featureService.UrlFeatureService + "/layers?f=json";

       var webClient = new WebClient();

       var stream = await webClient.OpenReadTaskAsync(layersUrl);

       var serializer = new DataContractJsonSerializer(typeof(FeatureServiceInfo));

       var result = serializer.ReadObject(stream);

  }

Luke

View solution in original post

4 Replies
dotMorten_esri
Esri Frequent Contributor

Are you referring to the "GetAllDetails()" method? That's also there in the new SDK:

ArcGISDynamicMapServiceLayer.GetAllDetailsAsync Method

Btw, I would also suggest you take a look at the new Geodatabase support instead of using MPK files. It could mean you don't need to use local server, and you can render everything as feature layers are high performance. It might very well do everything you need.

0 Kudos
LukePatterson
New Contributor III

Thanks for your quick response. I will definitely take a look at the new Geodatabase support. I am about to check out direct access of shapefiles as well!

Cheers,

Luke

0 Kudos
LukePatterson
New Contributor III

I actually got this figured out. For anyone else looking for the same thing...the code sample below will get the FeatureServiceInfo which has a Layers property that returns the LayerServiceInfo.

var featureService = new LocalFeatureService(mpkPathText.Text);

await featureService.StartAsync();

  if (featureService.Status == LocalServiceStatus.Running)

  {

        var layersUrl = featureService.UrlFeatureService + "/layers?f=json";

       var webClient = new WebClient();

       var stream = await webClient.OpenReadTaskAsync(layersUrl);

       var serializer = new DataContractJsonSerializer(typeof(FeatureServiceInfo));

       var result = serializer.ReadObject(stream);

  }

Luke

dotMorten_esri
Esri Frequent Contributor

That's a lot more involved way to do it, but it also the best and most efficient way. Nice work

0 Kudos