CreateSharingDraft

Zusammenfassung

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

Auswertung

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.

Hinweis:

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)
ParameterErklärungDatentyp
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
Rückgabewert
DatentypErklärung
Object

Returns a MapServiceDraft class object.

Codebeispiel

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.")