I would like to generate a .sd file for a feature service through python.
A little information:
This process can be tedious if done by hand, so I have scripted most of it out. I can update the datasources for all of the mxds and create .sd files for map services just fine, but my problem is with the feature services. I cannot get the .sd file that I generate for feature services to run on the ArcGIS server. I have followed the instructions in example 7 of this page: ArcGIS Help (10.2, 10.2.1, and 10.2.2) , but every time I upload the .sd file to manager, i get the following error:
Could not find resource or operation 'FeatureServer' on the system.
Here is my python code to create the .sddraft file.
def make_sd_draft(mxdPath, serviceName):
mxd = arcpy.mapping.MapDocument(mxdPath)
tempDir = mxdPath.replace(ntpath.basename(mxdPath), "")
"""Ceate a draft SD and modify the properties to overwrite an existing FS."""
arcpy.env.overwriteOutput = True
# All paths are built by joining names to the tempPath
SDdraft = os.path.join(tempDir, serviceName + ".sddraft")
newSDdraft = os.path.join(tempDir, serviceName + "_updated.sddraft")
arcpy.mapping.CreateMapSDDraft(mxd, SDdraft, serviceName, "MY_HOSTED_SERVICES")
#open the SDDraft file and replace any " entities with something else that we can restore later
replaceInFile(SDdraft, '"', 'zzzzzQuotezzzzz')
# Read the contents of the original SDDraft into an xml parser
doc = ET.parse(SDdraft)
root_elem = doc.getroot()
if root_elem.tag != "SVCManifest":
raise ValueError("Root tag is incorrect. Is {} a .sddraft file?".format(SDDraft))
# Change service type from map service to feature service
for config in doc.findall("./Configurations/SVCConfiguration/TypeName"):
if config.text == "MapServer":
config.text = "FeatureServer"
#Turn off caching
for prop in doc.findall("./Configurations/SVCConfiguration/Definition/" + "ConfigurationProperties/PropertyArray/" + "PropertySetProperty"):
if prop.find("Key").text == 'isCached':
prop.find("Value").text = "false"
for prop in doc.findall("./Configurations/SVCConfiguration/Definition/Extensions/SVCExtension"):
if prop.find("TypeName").text == 'KmlServer':
prop.find("Enabled").text = "false"
# Turn on feature access capabilities
for prop in doc.findall("./Configurations/SVCConfiguration/Definition/Info/PropertyArray/PropertySetProperty"):
if prop.find("Key").text == 'WebCapabilities':
prop.find("Value").text = "Query,Create,Update,Delete,Uploads,Editing"
# Add the namespaces which get stripped, back into the .SD
root_elem.attrib["xmlns:typens"] = 'http://www.esri.com/schemas/ArcGIS/10.1'
root_elem.attrib["xmlns:xs"] = 'http://www.w3.org/2001/XMLSchema'
# Write the new draft to disk
with open(newSDdraft, 'w') as f:
doc.write(f)
f.close()
return newSDdraft
this may help, read to the bottom.
How to Overwrite ArcGIS Server (on-premise) Featur... - Esri Community