Modifying Service Definition Draft file to enable WMS capabilities?

790
9
07-14-2021 05:21 AM
RehanChaudhary
New Contributor III

I am trying to automate the process of publishing WMS services directly from a raster file without using a map document or project file. I am able to publish an imagery layer or a map image layer but when i try to modify the image draft file to enable the WMS or WFS capabilities and create a new draft file it displays a black image for the image layer and the WMS. Probably because the information from previous file is not copied to the new file and i am not referencing the data in my workflow but rather copying it to the server. How can i enable WMS on my layer? Here is how i implement the image draft file:

 

 

 

arcpy.CreateImageSDDraft(rasterimage, output_draft, service, 'FROM_CONNECTION_FILE', con, True, None, "netCDF test", "test,auto")

 

 

 

Here is how i enable WMS :

 

 

 

doc=DOM.parse(output_draft)
typeNames = doc.getElementsByTagName('TypeName')
for typeName in typeNames:
    # Get the TypeName whose properties we want to modify.
    if typeName.firstChild.data == "WMSServer":
        extension = typeName.parentNode
        for extElement in extension.childNodes:
            # Enabled SOE.
            if extElement.tagName == 'Enabled':
                extElement.firstChild.data = 'true'

 

 

 

 Here is how i create a new draft file for storing updated  properties. and here is the problem. The info from previous file is lost and so i see a black image:

 

 

 

 

new_draft=r"C:/Users/C/arcgis/image1.sddraft"
f = open(new_draft, 'w')     
doc.writexml( f )     
f.close()   

 

 

0 Kudos
9 Replies
Borch
by
New Contributor II

Dear Rehan,

I share with you the function that I use to enable the WMS capability. The only difference is that I work with CreateMapSDDraft.

def enableWMS(sddraft):
    # These are the properties we will change in the sddraft xml.
    soe = 'WMSServer'

    # Read the sddraft xml.
    doc = DOM.parse(sddraft)
    # Find all elements named TypeName. This is where the server object extension (SOE) names are defined.
    typeNames = doc.getElementsByTagName('TypeName')
    for typeName in typeNames:
        # Get the TypeName whose properties we want to modify.
        if typeName.firstChild.data == soe:
            extension = typeName.parentNode
            for extElement in extension.childNodes:
                # Enabled SOE.
                if extElement.tagName == 'Enabled':
                    extElement.firstChild.data = 'true'
                    break

    keys = doc.getElementsByTagName('Key')
    for key in keys:
        if key.hasChildNodes():
            if key.firstChild.data == 'isCached':
                key.nextSibling.firstChild.data = 'false'
            elif key.firstChild.data == 'cacheOnDemand':
                key.nextSibling.firstChild.data = 'false'


    outXml = sddraft
    if os.path.exists(outXml): os.remove(outXml)
    f = open(outXml, 'w')
    doc.writexml(f)
    f.close()

    del f, doc
0 Kudos
RehanChaudhary
New Contributor III

@Borch unfortunately this still gives the same result

0 Kudos
ZikangZhou1
Esri Contributor

@RehanChaudhary 

Could you share the data you used?

If a WMS getMap returns things (even if it is black), that means WMS is working and the problem is more like a data rendering/visualization issue.

We could check the associated image service export image operation had it displayed well and start investigating from there. 

0 Kudos
RehanChaudhary
New Contributor III

@ZikangZhou1 i am using a netcdf file from esri and then copying its multidimensional raster layer to a raster dataset (crf). After that, i am using the CreateImageSddraft function and not the getMap as i want to publish directly from the file and not the map document. I have added the file and if required i can share the complete workflow as well.
One more thing, if i change the raster dataset from .crf to .tif then i get an error for a WMS layer which is below while the imagery layer is displayed in grayscale.


The WMS service, https://xyz.com/image/services/image/ImageServer/WMSServer, cannot be added to the map. It is either not available or you have entered an invalid URL for the type of layer you want to reference.

0 Kudos
Zikang
by
New Contributor

@RehanChaudhary 

I cannot reproduce the problem using my Pro 2.8 and Server 10.9 with your data. Here are my steps:

1. download your netcdf, run make multidimensional raster layer tool with the netcdf.

2. run copy raster tool, select process as multidimensional, output format as crf.

3. run the exact code snippet you provided to generate the sddraft file.

4. stage the sddraft file to make it a sd file; upload the sd file to server.

5. add the wms endpoint to arcgis pro as a new wms server, the layer displays just fine.

Zikang_0-1626392438544.png

 

0 Kudos
RehanChaudhary
New Contributor III

@Zikang i finally upload it to a federated esri arcgis portal and that is where i get the above mentioned error that it cannot be added to the map. When i see the layer detail it gives me error code 499 which is related to making the service public as currently it is set to private. I tried making it public directly from the portal but that did not help. How can i make it public using the functions of creating draft file and staging files to server and maybe that might solve the problem?

 

 

 

0 Kudos
ZikangZhou1
Esri Contributor
OK. Now I see the reason. Your service is a private one and it will always need a "token" parameter to access the wms. You may add a long-term token as an additional parameter when access via wms server connection.
Alternatively, you can make the item public through your portal, that will help as well.
Service definition doesn't have a such thing defined inside. You could try arcgis python api to make an item public after it is created. https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.share
0 Kudos
RehanChaudhary
New Contributor III

@ZikangZhou1 i tried making it public through my portal but that did not solve the problem. How can i add a token parameter?

 

0 Kudos
Zikang
by
New Contributor
Rehan,
Try some of arcgis portal documentations such as: https://enterprise.arcgis.com/en/portal/latest/administer/windows/specify-the-default-token-expirati...
Theoretically, making it public through portal should have resolved the problem.
This is getting out of my expertise right now. Could you reach out to esri technical support for this?
0 Kudos