IAGSServerConnectionFactory connectionFactory = new AGSServerConnectionFactory();
IPropertySet propertySet = new PropertySet();
IAGSServerConnection connection;
propertySet.SetProperty("url", "http://meng/arcgis/services");
connection = connectionFactory.Open(propertySet, 0);
// Get "MapService" MapServer object
IAGSEnumServerObjectName serverObjectNames;
IAGSServerObjectName serverObjectName;
serverObjectNames = connection.ServerObjectNames;
while ((serverObjectName = serverObjectNames.Next()) != null)
{
if (serverObjectName.Name.Equals("zhyxk") && serverObjectName.Type.Equals("MapServer"))
break;
}
if (serverObjectName == null)
return;
IName name = serverObjectName as IName;
IMapServer mapServer = name.Open() as IMapServer;
// Create MapServerLayer using AGS data source
ESRI.ArcGIS.Carto.IMapServerLayer layer = new MapServerLayer() as IMapServerLayer;
layer.ServerConnect(serverObjectName, mapServer.DefaultMapName);
axMapControl1.AddLayer(layer as ILayer);
axMapControl1.Refresh();