GISClient类库允许开发者使用Web服务,这些Web服务可以由ArcIMS和ArcGIS Server提供。GISClient类库中包含用于连接GIS服务器以使用Web服务的对象。该类库支持ArcIMS的图像和要素服务。GISClient类库提供以无态方式直接或通过Web服务目录操作ArcGIS Server对象的通用编程模型。在ArcGIS Server上运行的ArcObjects组件不能通过GISClient接口来访问。要直接获得访问在服务器上运行的ArcObjects,开发人员应使用Server类库中的功能。
- 打开连接
<span style="font-size:18px;">private void OpenConn(bool bLAN,string sval)
{
try
{
IAGSServerConnectionFactory pConnF = new AGSServerConnectionFactory();
IPropertySet pProSet = new PropertySet();
if(bLAN)
pProSet.SetProperty("machine", sval);
else
pProSet.SetProperty("url", sval);
clsPublic.pConn = pConnF.Open(pProSet, 0);
if (clsPublic.pConn != null)
{
MessageBox.Show("连接成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("连接失败","提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch { }
}
</span>
- 加载地图服务
<span style="font-size:18px;">public void AddMapService(AxMapControl pMapCtrl, string sServiceName, IAGSServerConnection pConn)
{
pConn.ServerObjectNames.Reset();
IAGSEnumServerObjectName pEnumServerObjectNames = pConn.ServerObjectNames;
pEnumServerObjectNames.Reset();
IAGSServerObjectName pServerObjectName = pEnumServerObjectNames.Next();
IAGSServerObjectName sServerObjectName = null;
while (pServerObjectName != null)
{
if (pServerObjectName.Name == sServiceName)
{
sServerObjectName = pServerObjectName;
break;
}
pServerObjectName = pEnumServerObjectNames.Next();
}
if (sServerObjectName == null)
{
MessageBox.Show("没有找到对应的MapService", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
IName pName = sServerObjectName as IName;
IMapServer pMapServer = pName.Open() as IMapServer;
IMapServerLayer pMSLyr = new MapServerLayerClass();
pMSLyr.ServerConnect(sServerObjectName, pMapServer.DefaultMapName);
ILayer plyr = pMSLyr as ILayer;
pMapCtrl.ClearLayers();
pMapCtrl.AddLayer(plyr);
pMapCtrl.Extent = pMapCtrl.FullExtent;
}</span>
- 效果截图