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);
}