Hi,
I am implementing a script to publish web layer in bulk into Enterprise ArcGIS Server v10.7.0 based on below example.
https://pro.arcgis.com/en/pro-app/arcpy/sharing/mapservicedraft-class.htm
What I am trying is to create a Pro project file which has several maps having multiple feature classes sourced from EGDB, create a script to get all maps and layers in the project file, and publish each of layers as a web layer by reference. Our ArcGIS server is federated.
import arcpy
from arcpy import env
import os
aprxFile = r"pathto\Bulk_Layer_Publishing.aprx"
outDir = r"pathto\Output_sd"
# Reference map to publish
aprx = arcpy.mp.ArcGISProject(aprxFile)
for m in aprx.listMaps('*'):
print("Map: " + m.name)
serverFolder = m.name
serviceDirName = "{}\\{}".format(outDir, m.name)
if not os.path.exists(serviceDirName):
os.mkdir(serviceDirName)
for lyr in m.listLayers():
service_name = lyr.name
sddraft_filename = "{}\\{}".format(serviceDirName, service_name + ".sddraft")
# Create MapServiceDraft and set service properties
sharing_draft = arcpy.sharing.CreateSharingDraft('STANDALONE_SERVER', 'MAP_SERVICE', service_name, lyr)
targetServer = r"pathTo\MyArcGIS.ags"
sharing_draft.targetServer = targetServer
sharing_draft.serverFolder = serverFolder # same as Map name
sharing_draft.copyDataToServer = False
sharing_draft.exportToSDDraft(sddraft_filename)
Error: Target server is not a standalone server or is inaccessible.
Traceback (most recent call last):
File "<string>", line 45, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sharing.py", line 91, in exportToSDDraft
return _convertArcObjectToPythonObject(self._arc_object.exportToSDDraft(out_sddraft,self))
ValueError: Target server is not a standalone server or is inaccessible.
Could anyone advise me what's wrong with my code??
Thanks.