Select to view content in your preferred language

Adding a authenticated WMS layer to a LayerFile using ArcObjects

1985
1
05-14-2010 11:09 AM
FrankEvans
New Contributor
I need to programmatically generate a LayerFile which contains a WMS Layer using ArcObjects. The WMS Server is authenticated. I want to define the WMS Layer within the mapfile, and allow the user to provide credentials when he opens it in ArcMap.

But it seems that the process of constructing a WMSLayer in ArcObjects requires connecting. See example below. The problem is, the entity running this code doesn't have credentials.

QUESTION:
Is ther any way to add a WMS Layer to a LayerFile without connecting?


CODE: THIS CODE WORKS BUT IT REQURES CREDENTIALS.
IDataLayer pDataLayer = (IDataLayer)pWMSMapLayer;
pDataLayer.Connect((IName)wmsConnect);
ESRI.ArcGIS.GISClient.IWMSServiceDescription pWMSServiceDescription = pWMSMapLayer.WMSServiceDescription;

for (int i = 0; i < pWMSServiceDescription.LayerDescriptionCount; i++)
{
    ESRI.ArcGIS.GISClient.IWMSLayerDescription pLayerDesc = pWMSServiceDescription.get_LayerDescription(i);
    IWMSLayer pNewWMSLayer = pWMSMapLayer.CreateWMSLayer(pLayerDesc);
    ILayer pNewLayer = (ILayer)pNewWMSLayer;
    pWMSMapLayer.InsertLayer(pNewLayer, 0);
}
0 Kudos
1 Reply
KirkKuykendall
Deactivated User
Have you tried calling ISecureLayer2.ClearPassword before saving the mxd (or .lyr file)?
0 Kudos