AnsweredAssumed Answered

How to Overwrite ArcGIS Server (on-premise) Feature Service with Python?

Question asked by mbabinski1988 on Apr 2, 2015
Latest reply on Oct 20, 2015 by henry296

Greetings,

 

I am working on a script tool that will overwrite an existing service, with the option to identify it as a feature service. I'm using ArcGIS 10.2.0. When I run the script (abstracted and included below) with the feature service option activated, I consistently get an error of:

 

 

The script tool takes three parameters:

 

  1. Service Folder - Rest Endpoint (String)
  2. Service Name (String)
  3. Is Feature Service (bool)

 

The workflow I am following is

 

  1. Create Map SD draft
  2. Update the SVCManifest/TypeName portion of the SD draft xml to be "esriServiceDefinitionType_replacement"
  3. If the feature service option is selected, modify the XML to specify TypeName of FeatureServer, State of esriSDState_Published, turn off caching, and grant full web capabilities including Query,Create,Update,Delete,Uploads,Editing
  4. Save the updated xml to the disk
  5. Stage the service
  6. Upload the service definition if there are no errors

 

The script is attached. Based on my research so far, my best guess is that my modifications to the XML are somehow invalidating it. Here is that specific portion:

 

# Identify the SD draft to use
if str(is_feature_service) == "true":
    xml = newSDdraft
else:
    xml = sddraft


# Set service type to esriServiceDefinitionType_Replacement
newType = 'esriServiceDefinitionType_Replacement'
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
    if desc.parentNode.tagName == 'SVCManifest':
        if desc.hasChildNodes():
            desc.firstChild.data = newType


# If feature service is selected, change the service type from map service to feature service
if str(is_feature_service) == "true":
    typeNames = doc.getElementsByTagName('TypeName')
    for typeName in typeNames:
        if typeName.firstChild.data == "MapServer":
            typeName.firstChild.data = "FeatureServer"


    tagsState = doc.getElementsByTagName('State')
    for tagState in tagsState:
        if tagState.parentNode.tagName == 'SVCManifest':
            if tagState.hasChildNodes():
                tagState.firstChild.data = "esriSDState_Published"


    # ...turns off caching
    configProps = doc.getElementsByTagName('ConfigurationProperties')[0]
    propArray = configProps.firstChild
    propSets = propArray.childNodes
    for propSet in propSets:
        keyValues = propSet.childNodes
        for keyValue in keyValues:
            if keyValue.tagName == 'Key':
                if keyValue.firstChild.data == "isCached":
                    keyValue.nextSibling.firstChild.data = "false"


    # ...and turn on feature access capabilities
    configProps = doc.getElementsByTagName('Info')[0]
    propArray = configProps.firstChild
    propSets = propArray.childNodes
    for propSet in propSets:
        keyValues = propSet.childNodes
        for keyValue in keyValues:
            if keyValue.tagName == 'Key':
                if keyValue.firstChild.data == "WebCapabilities":
                    keyValue.nextSibling.firstChild.data = "Query,Create,Update,Delete,Uploads,Editing"


    # Write the new draft to disk
    f = open(newSDdraft, 'w')
    doc.writexml( f )
    f.close()

 

The full script is attached. Any guesses or help would be much appreciated! Most of the help for overwriting a feature service that I found was for hosted feature services, so I'm a bit at a loss.

 

Regards,

 

Micah Babinski

Outcomes