Creates a MapServiceDraft from a Map in an ArcGIS Pro project.


The CreateSharingDraft function creates a MapServiceDraft from a Map in an ArcGIS Pro project that can be configured and shared to ArcGIS Server. A MapServiceDraft is a configurable set of properties for a map service. After the sharing draft is configured, it can be saved to a service definition draft (.sddraft) file using the exportToSDDraft function from the MapServiceDraft class. The service definition draft can then be staged and shared to ArcGIS Server using the Stage Service and Upload Service Definition tools.

Remarque :

Staging and sharing a service definition draft requires ArcGIS Server 10.6 or a later version.


CreateSharingDraft (server_type, service_type, service_name, draft_value)
ParamètreExplicationType de données

The server type. The following server type is supported:

  • STANDALONE_SERVERSupports publishing a map service to ArcGIS Server.

The service type. The following service type is supported:

  • MAP_SERVICESupports publishing a map service to ArcGIS Server.

The name of the service. The name can only contain alphanumeric characters and underscores; spaces and special characters are not supported. The name cannot be more than 120 characters in length.


A Map, Layer or list of layers. You can use a subset of layers from a map to publish.

Valeur renvoyée
Type de donnéesExplication

Returns a MapServiceDraft class object.

Exemple de code

MapServiceDraft example

The following script publishes a Map in an ArcGIS Pro project as a Map Service to ArcGIS Server.

import arcpy
import os

# Set output file names
outdir = r"C:\Project\Output"
service = "MapServiceDraftExample"
sddraft_filename = service + ".sddraft"
sddraft_output_filename = os.path.join(outdir, sddraft_filename)

# Reference map to publish
aprx ="C:\Project\World.aprx")
m = aprx.listMaps("World")[0]

# Create MapServiceDraft and set service properties
service_draft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER", "MAP_SERVICE", service, m)
service_draft.targetServer = r"C:\Project\ (publisher).ags"

# Create Service Definition Draft file

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

# Share to portal
print("Uploading Service Definition...")
arcpy.UploadServiceDefinition_server(sd_output_filename, r"C:\Project\ (publisher).ags")

print("Successfully Uploaded service.")

Rubriques connexes