Get Data Source for ArcGIS Map Service Layers

12898
16
Jump to solution
05-24-2016 03:47 PM
MeleKoneya
Occasional Contributor III

I am looking for some programmatic way to get the underlying data source used for a Map Service Layer.    We use mostly SDE layers, so I would like the Feature Class Name.    

I was able to do this with ArcObjects with C# .NET prior to 10.1 but I don't believe it can be done the same way due to the changes in ArcGIS Server architecture

Does anyone have any code examples of getting the layer sources?

I may end up using the MXD to compile data sources,  but would like to go against the map services directly if possible.

Thanks,

Mele

0 Kudos
16 Replies
MeleKoneya
Occasional Contributor III

Found this presentation that helped me out:

Home | Esri Video 

MeleKoneya
Occasional Contributor III

This is what I ended up doing with the GitHub Code from Philip Heede.   Works great.

https://github.com/pheede/agsadmin-devsummit

static async Task DoWork()
        {
            AGSClient Client = new AGSClient("https://server:6080/arcgis/admin/", "user", "pwd");

           

            await Client.Authenticate();

            Console.Out.WriteLine("Authenticated against {0}: {1}", Client.ServerUrl, Client.IsAuthenticated);
            Console.Out.WriteLine("Session expires at {0}", Client.TokenExpiration.ToLocalTime());
            Console.Out.WriteLine("------------------");


           
            // get status of all services in all folders

            var folders = await Client.GetFolderNames();

            Console.Out.WriteLine("The following folders are defined on the server:");
            Console.Out.WriteLine("/");
            foreach (string folder in folders)
            {
                Console.Out.WriteLine(folder);
            }
            Console.Out.WriteLine("------------------");

            var taskServiceReports = await Client.GetAllServiceReports();

            foreach (string folder in taskServiceReports.Keys)
            {
                Console.Out.WriteLine(folder);
                foreach (var report in taskServiceReports[folder])
                {
                    Console.Out.WriteLine(folder);
                    Console.Out.WriteLine(string.Format(" - {0}: {1}", report.serviceName, report.status.realTimeState.ToString()));
                    var manifest = await Client.GetServiceManifest(report, report.folderName);

                    foreach (var db in manifest.databases)
                    {
                        //Console.Out.WriteLine(db.onPremiseConnectionString);
                        foreach (var ds in db.datasets)
                        {
                            Console.Out.WriteLine(ds.onServerName);
                            
                        }
                    }
                  

                }
            }
            Console.Out.WriteLine("------------------");
           
           
        }

SE_GIS_BWDB
New Contributor

link is dead

0 Kudos
ModyBuchbinder
Esri Regular Contributor

When you publish mxd to map service the mxd is copied to C:\arcgisserver\directories\arcgissystem\arcgisinput\<serviceName>.MapServer\extracted\v101\<serviceName).mxd

You can get this file, open it (arcpy or ArcObjects) and get all information.

Do not change it!!

Have fun

Mody

TomBell1
New Contributor III

Thank you!  Thank you!

0 Kudos
Arne_Gelfert
Occasional Contributor III

the server copy of the MXD seems to be a very little known fact that I just recently had to explain to someone. It would be crazy to think the link between map service and MXD would otherwise be lost. What I've used is something like the below. I can run this locally if I've shared the server directory.:

import glob
for item in glob.glob('//myserver/arcgisserver/directories/arcgissystem/arcgisinput/**/*.mxd',recursive=True):
   print(item)