ArcEngine中加载ArcGIS Server地图服务

代码如下:

 

private void addMapServerLayer(object sender, EventArgs e)

 {
            IActiveView pActiveView 
= m_mapControl.Map as IActiveView;
            IAGSServerObjectName3 pAGSServerObjectName3 
= GetAGSServerConnectionName();
            IName name 
= (IName)pAGSServerObjectName3;
            IMapServer  pMapServer 
= (IMapServer)name.Open();
            IMapServerLayer pMapServerLayer 
= new MapServerLayerClass();
            pMapServerLayer.ServerConnect(pAGSServerObjectName3, pMapServer.DefaultMapName);
            ILayer pLayer 
= pMapServerLayer as ILayer;
            m_mapControl.AddLayer(pLayer, 
0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography , 
nullnull);
}

private IAGSServerObjectName3 GetAGSServerConnectionName()
{
            IAGSServerConnectionName2 agsServerConnectionName 
= new AGSServerConnectionName() as IAGSServerConnectionName2 ;
            IPropertySet props 
= new PropertySetClass();
            props.SetProperty(
"machine", machine_name);
            agsServerConnectionName.ConnectionProperties 
= props;

            IAGSSer verObjectName3 agsServerObjectName 
= new AGSServerObjectNameClass();
            agsServerObjectName.Name 
= server_name;
            agsServerObjectName.Type 
= "MapServer";
            agsServerObjectName.AGSServerConnectionName 
= agsServerConnectionName;
            
return agsServerObjectName;
}
posted @ 2009-07-21 20:40  因是因非  阅读(2629)  评论(0编辑  收藏  举报