AnsweredAssumed Answered

Create FeatureService .sd file of MXD using  .sde connection through python

Question asked by BronleyPlumb_1 on Jan 23, 2015

I would like to generate a .sd file for a feature service through python.

 

A little information:

  • We are using ArcGIS Server 10.2.2
  • We are using an oracle database to house all of the data. GeoDatabases are not an option. It must be oracle.
  • All mxds connect to layers in the oracle database through .sde files
  • We are publishing map services for viewing in a browser, and feature services for editing data in a browser.
  • We do not have direct access to the ArcGIS Servers. We have to give all of the required ArcGIS content to an employee who is responsible for doing the migrations.
  • We have three environments: dev, test, prod. Every time we update an mxd, we need to do the following:
    • set datasources on every mxd to point to the corresponding environments.
    • create .sd files to give to the employee responsible for the migrations

 

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

Outcomes