Arcgis Engine连接ArcGis Server

  1.Server端连接

            ESRI.ArcGIS.Server.GISServerConnectionClass gisconnection= new ESRI.ArcGIS.Server.GISServerConnectionClass();
            gisconnection.Connect("localhost");
            ESRI.ArcGIS.Server.IServerObjectManager som = gisconnection.ServerObjectManager;
            string servertype = "MapServer";
            string serverobjectname = "china";
            ESRI.ArcGIS.Server.IServerContext servercontext = som.CreateServerContext(serverobjectname, servertype);
            IMapServer ms = (IMapServer)servercontext.ServerObject;
            IMapServerObjects pMapServerObjs = ms as IMapServerObjects;
            IMap pMap = pMapServerObjs.get_Map(ms.DefaultMapName);
            for (int i = 0; i < pMap.LayerCount;i++ )
            {
                IFeatureLayer pFLayer = pMap.get_Layer(i) as IFeatureLayer;
                IFeatureClass pFeatureClass = pFLayer.FeatureClass;
                Console.WriteLine(pFeatureClass.FeatureCount(null).ToString());
            }
            servercontext.ReleaseContext();

2. Engine连接Server

(1)    IAGSServerObjectName pServerObjectName = GetMapServer("机器名或者URL", "china", true);
            IName pName = (IName)pServerObjectName;
            //访问地图服务
            IMapServer pMapServer = (IMapServer)pName.Open();


            ESRI.ArcGIS.Carto.IMapServerLayer pMapServerLayer = new ESRI.ArcGIS.Carto.MapServerLayerClass();
            //连接地图服务

            pMapServerLayer.ServerConnect(pServerObjectName, pMapServer.DefaultMapName);


            axMapFull.AddLayer(pMapServerLayer as ILayer);//这里会把服务中的图层合成一个图层来显示,虽然看起来

            //和服务中的地图一样

            axMapFull.Refresh();

(2)

        public IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
        {

            //设置连接属性
            IPropertySet pPropertySet = new PropertySetClass();

            if (pIsLAN)
                pPropertySet.SetProperty("machine", pHostOrUrl);//machine可以是机器名或者IP,连接方式为LAN。
            else
                pPropertySet.SetProperty("url", pHostOrUrl);//如果url连接的需要设置用户名和密码,那么要设置用户名和密码属性。

             //如果使用url连接,那么一定要在浏览器可以访问才行。


            //打开连接
           
            IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory();

            IAGSServerConnection pConnection = pFactory.Open(pPropertySet, 0);

            //Get the image server.
            IAGSEnumServerObjectName pServerObjectNames = pConnection.ServerObjectNames;
            pServerObjectNames.Reset();
            IAGSServerObjectName ServerObjectName = pServerObjectNames.Next();
            while (ServerObjectName != null)
            {
                if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) &&
                    (ServerObjectName.Type == "MapServer"))
                {

                    break;
                }
                ServerObjectName = pServerObjectNames.Next();
            }

            //返回对象
            return ServerObjectName;
        }

3.ADF连接
            ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity("user", "passwd", "domain");
            ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection ags_connection;
            agsconnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection("hostname", identity);
            agsconnection.Connect();
            IServerObjectManager som = agsconnection.ServerObjectManager;

转载于:https://www.cnblogs.com/liujp/archive/2012/11/12/2766529.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值