# edit configuration properties
configProps = doc.getElementsByTagName(''ConfigurationProperties'')[0]
propArray = configProps.firstChild
propSets = propArray.childNodes
for propSet in propSets:
keyValues = propSet.childNodes
for keyValue in keyValues:
if keyValue.tagName == ''Key'':
if keyValue.firstChild.data == enableDynamicLayers:
keyValue.nextSibling.firstChild.data = true
# output to a new sddraft
outXml = rE:\Temp\Python\Airports_New.sddraft
if os.path.exists(outXml): os.remove(outXml)
f = open(outXml, ''w'')
doc.writexml( f )
f.close()
再通过arcpy将sdddraft文件转换为.sd文件发布;
2. 通过arcpy正常流程发布服务后,再修改服务属性,如:
#modify these to match your environment
serverHost = ''yourgisServer.com''
serverPort = 6080
serviceRelativePath = r''/services/serviceFolder/serviceName.MapServer''
username = ''yourAdminName''
password = ''yourAdminPW''
# properites you would like to apply to the service
newProperties = {
minInstancesPerNode: 1,
maxInstancesPerNode: 5,
properties: {
enableDynamicLayers: true,
dynamicDataWorkspaces: [{\id\:\wsName\,\workspaceFactory\:\SDE\,\lockVersion\:\false\,\workspaceConnection\:\connectionProps\}]
}
}
import json
import urllib
import httplib
# ####################
# helper functions
# ####################
def getUpdatedDict(inDict,modDict):
def _getPathsAndValuesFromModDict(d,parentDict):
for k, v in d.iteritems():
if isinstance(v, dict):
_getPathsAndValuesFromModDict(v,parentDict[k])
else:
parentDict[k] = v
_getPathsAndValuesFromModDict(modDict,inDict)
return inDict
def adminApiCall(strAdminApiUrl,objParams):
def _getToken():
tokenURL = /arcgis/admin/generateToken
params = urllib.urlencode({''username'': username, ''password'': password, ''client'': ''requestip'', ''f'': ''json''})
headers = {Content-type: application/x-www-form-urlencoded, Accept: text/plain}
httpConn = httplib.HTTPConnection(serverHost, serverPort)
httpConn.request(POST, tokenURL, params, headers)
response = httpConn.getresponse()
if (response.status != 200):
httpConn.close()
return
else:
data = response.read()
httpConn.close()
# Check that data returned is not an error object
if not _assertJsonSuccess(data):
return
# Extract the toke from it
token = json.loads(data)
return token[''token'']
def _assertJsonSuccess(data):
obj = json.loads(data)
if ''status'' in obj and obj[''status''] == error:
#print Error: JSON object returns an error. + str(obj)
return False
else:
return True
# Check that data returned is not an error object
if not _assertJsonSuccess(data):
obj = json.loads(data)
output = obj[''messages'']
else:
dataObj = json.loads(data)
output = dataObj
httpConn.close()
try:
if output[0] == u''Authorization failed. This user account does not have the required privileges to access this application.'':
return {''status'':''error'',''msg'':u''Authorization failed for user''}
except:
return output
# ####################
# end helper functions
# ####################
#fetch the parameters using the admin api
serviceInfo = adminApiCall(serviceRelativePath,{''f'':''json''})
#update new parameters using the new properties
serviceInfo = getUpdatedDict(serviceInfo,newProperties)
#apply the updated params
adminApiCall(''/services/test/testForDave.MapServer/edit'',{''f'':''json'',''service'':json.dumps(serviceInfo)})
1 个回复
刘峥 - ArcGIS多面手
赞同来自:
有两种方式,第二种相对简单一点:
1. 在发布时通过xml.dom.minidom库编辑xml文件,设置enableDynamicLayers为true,如:
再通过arcpy将sdddraft文件转换为.sd文件发布;
2. 通过arcpy正常流程发布服务后,再修改服务属性,如:
参考链接:https://geonet.esri.com/thread/171267
要回复问题请先登录或注册