ListMapServices (arcpy.mapping)

Récapitulatif

LegacyLegacy :

This method has been deprecated at ArcGIS 10.1 and will return a runtime error. Please consult the ArcGIS documentation for the usage of the new ArcGIS for Server Administrator API.

Lists the names of map services for a designated ArcGIS for Server.

Discussion

This method has been deprecated at ArcGIS 10.1 and will return a runtime error.

ArcGIS for Server 10.1 has a new architecture, which may require you to adjust how you work with the server. See the following help topics for more information: What's new in ArcGIS 10.1 for Server, What to expect when migrating to ArcGIS 10.1 for Server and Migration to ArcGIS 10.1 for Server.

You can list Map Services using the ArcGIS for Server Administrator API which is available through the ArcGIS Site Directory. The default URL of the ArcGIS for Server Site Directory is as follows:

http://<server name>:6080/arcgis/admin

RemarqueRemarque :

The URL of the Site Directory may vary if you have configured ArcGIS for Server Web Adaptor to work with your site. For example, the inclusion of the port number, 6080, may not be required. Check your web adaptor configuration to obtain the correct URL.

An example of using Python and the ArcGIS for Server Administrator API to list Map Services is below:

RemarqueRemarque :

A code sample to generate an ArcGIS for Server token can be found here: DeleteMapService

import json, urllib2

server = "<server>"
port = "6080"
token = '<token string>'
baseUrl = "http://{}:{}/arcgis/admin/services".format(server, port)

def getCatalog(token):
  catalog = json.load(urllib2.urlopen(baseUrl + "/" + "?f=json&token=" + token))
  print 'Root' 
  if "error" in catalog: return
  services = catalog['services']
  for service in services:
    response = json.load(urllib2.urlopen(baseUrl + '/' + service['serviceName'] + '/' + service['type'] + "?f=json&token=" + token))
    print '  %s %s (%s)' % (service['serviceName'], service['type'], 'ERROR' if "error" in response else 'SUCCESS')
  folders = catalog['folders']
  for folderName in folders:
    catalog = json.load(urllib2.urlopen(baseUrl + "/" + folderName + "?f=json&token=" + token))
    print folderName
    if "error" in catalog: return
    services = catalog['services']
    for service in services:
      response = json.load(urllib2.urlopen(baseUrl + '/' + service['serviceName'] + '/' + service['type'] + "?f=json&token=" + token))
      print '  %s %s (%s)' % (service['serviceName'], service['type'], 'ERROR' if "error" in response else 'SUCCESS')

getCatalog(token)

You can also list Map Services using the ArcGIS for Server REST API which is available through the ArcGIS Services Directory. The default URL of the ArcGIS for Server Services Directory is as follows:

http://<server name>:6080/arcgis/rest/services

To get started using the ArcGIS for Server Services Directory and REST API, see the help within the Services Directory.

An example of using Python and the ArcGIS for Server REST API to list Map Services is below:

import json, urllib2

server = "<server>"
port = "6080"
baseUrl = "http://{}:{}/arcgis/rest/services".format(server, port)

def getCatalog():
  catalog = json.load(urllib2.urlopen(baseUrl + "/" + "?f=json"))
  print 'ROOT' 
  if "error" in catalog: return
  services = catalog['services']
  for service in services:
    response = json.load(urllib2.urlopen(baseUrl + '/' + service['name'] + '/' + service['type'] + "?f=json"))
    print '  %s %s (%s)' % (service['name'], service['type'], 'ERROR' if "error" in response else 'SUCCESS')
  folders = catalog['folders']
  for folderName in folders:
    catalog = json.load(urllib2.urlopen(baseUrl + "/" + folderName + "?f=json"))
    print folderName
    if "error" in catalog: return
    services = catalog['services']
    for service in services:
      response = json.load(urllib2.urlopen(baseUrl + '/' + service['name'] + '/' + service['type'] + "?f=json"))
      print '  %s %s (%s)' % (service['name'], service['type'], 'ERROR' if "error" in response else 'SUCCESS')

getCatalog()

Syntaxe

ListMapServices (connection_url_or_name, server, {connection_username}, {connection_password}, {connection_domain})
ParamètreExplicationType de données
connection_url_or_name

A string that represents the URL of the ArcGIS for Server to which you want to get a list of services.

String
server

A string that represents the ArcGIS for Server host name.

String
connection_username

A string that represents a user name used to connect to the ArcGIS for Server. In order to get a list of map services this user name should be a member of the ArcGIS for Server admin group. This variable is only necessary when connecting to a UNIX/Linux ArcGIS for Server.

(La valeur par défaut est None)

String
connection_password

A string that represents a password used to connect to the ArcGIS for Server. This variable is only necessary when connecting to a UNIX/Linux ArcGIS for Server.

(La valeur par défaut est None)

String
connection_domain

A string that represents a domain name used to connect to the ArcGIS for Server. This variable is only necessary when connecting to a UNIX/Linux ArcGIS for Server.

(La valeur par défaut est None)

String
Valeur renvoyée
Type de donnéesExplication
List

A Python list of map services.

9/12/2013