I am using ArcGIS Server 10.2 and am able to successfully use arcpy to publish MapServer and GeoCode services. However, I cannot find anything about publishing a FeatureServer service outside of initially publishing it as a MapServer service and then modifying it.
I have mxd's and they mostly get published as MapServer services using the general: arcpy.mapping.CreateMapSDDraft > StageService_server > UploadServiceDefinition_server commands. I want to be able to publish from mxd to FeatureServer service in much the same way as above. This seems like it was possible with the legacy msd files(old sd format). Like much else with ESRI I am perplexed at the lack of intuitive/complete documentation and features.
I have tried many ways of manipulating the sddraft file with xml.dom.minidom but to no avail. The analyze and stage commands say the draft is ok but then it throws a 001270 error. I have looked this error up and much of the solutions seem very inapplicable to my situation. I have tried pretty much everything I can find web searching for a solution so if anyone has any other knowledge it is much appreciated.
Solved! Go to Solution.
I have found my solution. In trying to understand this I got my memory mixed up and was looking at the xml of SD files and not the sddraft file created by ArcMap. Using a comparison tool I made a default MapServer service sddraft and one with the FeatureServer/Full Access capability turned on and the KmlServer turned off. It's actually very simple yet there is no examples or instructions on how to do it anywhere. ESRI's code is totally backwards in my opinion. Sparing everyone why it is wrong this is my code as pertaining to the xml editing part:
import arcpy
import xml.dom.minidom as DOM
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', con, False, None, summary, tags)
doc = DOM.parse(sddraft)
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
if typeName.firstChild.data == 'FeatureServer':
extention = typeName.parentNode
for extElement in extention.childNodes:
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
if typeName.firstChild.data == 'KmlServer':
extention = typeName.parentNode
for extElement in extention.childNodes:
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'false'
f = open(sddraft, 'w')
doc.writexml( f )
f.close()
Essentially all you have to do is change those 2 'Enabled' values. The sddraft in xml format is completely backwards which is what was messing me up. Each SVCExtension heading states no name and then proceeds to say whether it's enabled, then all of its properties and finally it's name.
Every time I try to tackle a ESRI coding issue I am unable to find relevant code, once I do find it I am unable to piece together anything relevant due to incorrect documentation and that's if the code isn't broken. The documentation is devoid of links to relevant datatypes (if they are even correct). I digress, and on I drudge...
I have found my solution. In trying to understand this I got my memory mixed up and was looking at the xml of SD files and not the sddraft file created by ArcMap. Using a comparison tool I made a default MapServer service sddraft and one with the FeatureServer/Full Access capability turned on and the KmlServer turned off. It's actually very simple yet there is no examples or instructions on how to do it anywhere. ESRI's code is totally backwards in my opinion. Sparing everyone why it is wrong this is my code as pertaining to the xml editing part:
import arcpy
import xml.dom.minidom as DOM
arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER', con, False, None, summary, tags)
doc = DOM.parse(sddraft)
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
if typeName.firstChild.data == 'FeatureServer':
extention = typeName.parentNode
for extElement in extention.childNodes:
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'true'
if typeName.firstChild.data == 'KmlServer':
extention = typeName.parentNode
for extElement in extention.childNodes:
if extElement.tagName == 'Enabled':
extElement.firstChild.data = 'false'
f = open(sddraft, 'w')
doc.writexml( f )
f.close()
Essentially all you have to do is change those 2 'Enabled' values. The sddraft in xml format is completely backwards which is what was messing me up. Each SVCExtension heading states no name and then proceeds to say whether it's enabled, then all of its properties and finally it's name.
Every time I try to tackle a ESRI coding issue I am unable to find relevant code, once I do find it I am unable to piece together anything relevant due to incorrect documentation and that's if the code isn't broken. The documentation is devoid of links to relevant datatypes (if they are even correct). I digress, and on I drudge...
This is the best answer for creating a feature service in python.