Skip To Content

CreateSharingDraft

Summary

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

Discussion

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.

Note:

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

Syntax

CreateSharingDraft (server_type, service_type, service_name, draft_value)
ParameterExplanationData Type
server_type

The server type. The following server type is supported:

  • STANDALONE_SERVERSupports publishing a map service to ArcGIS Server.
String
service_type

The service type. The following service type is supported:

  • MAP_SERVICESupports publishing a map service to ArcGIS Server.
String
service_name

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.

String
draft_value

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

List
Return Value
Data TypeExplanation
Object

Returns a MapServiceDraft class object.

Code sample

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 = arcpy.mp.ArcGISProject(r"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\myserver.ags.esri.com (publisher).ags"

# Create Service Definition Draft file
service_draft.exportToSDDraft(sddraft_output_filename)

# 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\myserver.ags.esri.com (publisher).ags")

print("Successfully Uploaded service.")