I am trying to write a script that creates feature layers in ArcGIS Enterprise based on layers in an ArcGIS Pro Project. I do not want to copy the data to the server, only reference it. The data comes out of a SDE database that is also registered with the respective ArcGIS Server.

While doing the process manually works well (right-click layer --> Share as Weblayer --> Reference registered data), if I try to do the same with Python, I always end up with a hosted feature layer, which means that the data has been copied to the server instead of referencing it.

This is the code I use. Am I missing something?

            featDraft = Map.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE", "REF_" + service6, layer)
            featDraft.copyDataToServer = "False"
            featDraft.description = metadata_description
            featDraft.portalFolder="REF_" + Mapname

            # Stage Service
            sd_filename = service6 + ".sd"
            sd_output_filename = os.path.join(outdir, sd_filename)
            arcpy.StageService_server(sddraft_output_filename, sd_output_filename, 5)

            # Share to portal
            print("Uploading Service Definition...")
            arcpy.UploadServiceDefinition_server(sd_output_filename, "My Hosted Services")

Follow up: Putting a arcpy.GetMessages(1) into my code gives me the following error:

WARNING 000710: Unable to connect to the server 

I assume that this means that the script is not able to access the database where the data resides to reference it. However, I am not sure where to put this information. Any ideas?

  • 1
    Are you using ArcPy or the ArcGIS API for Python ?
    – PolyGeo
    Sep 30 '20 at 9:53
  • This is arcpy, but I am open for solutions based on the ArcGIS API, too.
    – Martin
    Sep 30 '20 at 10:08
  • 1
    Look at the 2nd code example here for StageService and do the GetMessages and see if you're getting any warnings, like "data is not registered and will be copied". pro.arcgis.com/en/pro-app/tool-reference/server/…
    – KHibma
    Sep 30 '20 at 12:29
  • @KHibma : Thanks for the tip. I did as you suggested and get a warning, which I am not sure how to interprete correctly. I have adjusted my question accordingly
    – Martin
    Oct 1 '20 at 6:00

I found a solution to my problem: One has to create a MapImageSharingDraft instead of a FeatureSharingDraft. In a second step, one has to edit the created SDDraft-file (XML) to allow feature access. As a result, two services are being created (one Map Image Service and one Feature Service). Please check the second code sample from the following page (Modify SDDraft example). It includes a code block on how to edit the SDDraft-file: https://pro.arcgis.com/en/pro-app/arcpy/sharing/mapimagesharingdraft-class.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.