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:
The workflow I am following is
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
A couple of things.
1. Are you able to get any results during the analysis portion of staging the service and do they indicate any warnings/errors?
2. Are you sure that the underlying data is supported for a feature service.
This section of the ArcGIS Help gives more details on the feature service requirements...
http://resources.arcgis.com/en/help/main/10.2/0154/0154000003nt000000.htm
Hi Andrew,
I should have specified that I have not had any problems overwriting this feature service using the GUI-based workflow within arcmap:
My interest is really to be able to overwrite these types of services automatically for when I have to make bulk updates to layer and MXD descriptions, symbology, or other characteristics of the MXD.
Thanks,
Micah
Micah,
The help documentation about changing to a feature service appears to be applicable to ArcGIS Online hosted services. I got the following to work for ArcGIS Server:
#Enable FeatureServer
soe = 'FeatureServer'
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
if typeName.firstChild.data == soe:
extension = typeName.parentNode
for extElement in extension.childNodes:
if extElement.tagName =='Enabled':
extElement.firstChild.data ='true'
#Enable overwrite existing service
tagsType = doc.getElementsByTagName('Type')
for tagType in tagsType:
if tagType.parentNode.tagName == 'SVCManifest':
if tagType.hasChildNodes():
tagType.firstChild.data = "esriServiceDefinitionType_Replacement"
tagsState = doc.getElementsByTagName('State')
for tagState in tagsState:
if tagState.parentNode.tagName == 'SVCManifest':
if tagState.hasChildNodes():
tagState.firstChild.data = "esriSDState_Published"
# Turn off Allow Geometry Updates
configProps = doc.getElementsByTagName('Props')[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 == "allowGeometryUpdates":
keyValue.nextSibling.firstChild.data = "False"
# Get all the value tags.
values = doc.getElementsByTagName('Value')
for value in values:
if value.hasChildNodes():
# Change the default WebCapabilities from 'Query,Create,Update,Delete,Uploads,Editing' to just 'Query'.
if value.firstChild.data == 'Query,Create,Update,Delete,Uploads,Editing':
value.firstChild.data = 'Query,Update,Uploads,Editing'
However, the Turn off Allow Geometry Updates does not work. I can change it manually in the sddraft file, but that code does not edit the XML. Do you have any thoughts on what part should be changed to find the allowGeometryUpdates property.
I figured out the code to change the allow geometry updates.
This line configProps = doc.getElementsByTagName('Props')[0]
need to be configProps = doc.getElementsByTagName('Props')[1] because the Props
tag exists twice in the XML file.