How to get service name from ServiceGeodatabase?

282
1
Jump to solution
09-29-2022 05:18 AM
ViktorSafar
Occasional Contributor II

I have a ServiceGeodatabase constructed from a URL

https://services.arcgis.com/REDACTED/arcgis/rest/services/Parent_layer_attempt/FeatureServer

On the web interface I can see the name of the Feature service (in red) and the service ItemID.

How do I get any of these out of the ServiceGeodatabase object? I have looked all over the place but can't find it.

 

There is also the Info child resource (green) which then provides an ItemInfo child resource where there is a lot of information. Are these accessible via the Runtime API or do I need to make an HTTP call to .../FeatureServer/info/itemInfo?

 

ViktorSafar_0-1664453885608.png

ViktorSafar_1-1664453892920.png

 

0 Kudos
1 Solution

Accepted Solutions
MichaelBranscomb
Esri Frequent Contributor

If your service has a service id then it is from an ArcGIS Portal, in which it would probably be better to approach from the PortalItem perspective (example below). Note the way you access/create the portal item initially will be different from this public sample service example where I'm using the direct URL including the ItemId, for example the item might be returned from a portal search.

 

PortalItem portalItem = await PortalItem.CreateAsync(new Uri("https://www.arcgis.com/home/item.html?id=6f7540023c48421e923db1bb9b7d5414"));
ServiceGeodatabase serviceGeodatabase = new ServiceGeodatabase(portalItem.ServiceUrl);
await serviceGeodatabase.LoadAsync();
Regex regex = new Regex("services/(.*)/FeatureServer");
var v = regex.Match(serviceGeodatabase.ServiceInfo.Source.ToString());
string s = v.Groups[1].ToString();

 

Regarding the service name, the way you approach this may depend on what you need the value for. The portion of the service path that you highlight is just the service name. Accessing via the PortalItem itself gives you access to properties that might be more meaningful if presenting the information in the UI, for example string portalItem.Title (in this case "San Diego Facilities" versus the original service name "San_Diego_Facilities" - ok that's not a great comparison 😞 but the Title in theory could be more different and could mean more to the user). 

View solution in original post

0 Kudos
1 Reply
MichaelBranscomb
Esri Frequent Contributor

If your service has a service id then it is from an ArcGIS Portal, in which it would probably be better to approach from the PortalItem perspective (example below). Note the way you access/create the portal item initially will be different from this public sample service example where I'm using the direct URL including the ItemId, for example the item might be returned from a portal search.

 

PortalItem portalItem = await PortalItem.CreateAsync(new Uri("https://www.arcgis.com/home/item.html?id=6f7540023c48421e923db1bb9b7d5414"));
ServiceGeodatabase serviceGeodatabase = new ServiceGeodatabase(portalItem.ServiceUrl);
await serviceGeodatabase.LoadAsync();
Regex regex = new Regex("services/(.*)/FeatureServer");
var v = regex.Match(serviceGeodatabase.ServiceInfo.Source.ToString());
string s = v.Groups[1].ToString();

 

Regarding the service name, the way you approach this may depend on what you need the value for. The portion of the service path that you highlight is just the service name. Accessing via the PortalItem itself gives you access to properties that might be more meaningful if presenting the information in the UI, for example string portalItem.Title (in this case "San Diego Facilities" versus the original service name "San_Diego_Facilities" - ok that's not a great comparison 😞 but the Title in theory could be more different and could mean more to the user). 

0 Kudos