AE操作Server(3):加载服务

来源:互联网 发布:ui和美工的区别 编辑:程序博客网 时间:2024/04/29 09:54

1.引言

上一篇中介绍的是AE获取Server下的所有服务和服务信息,本篇中将介绍使用AE加载Server服务

2.代码

        /// <summary>        /// 加载地图服务数据        /// </summary>        /// <param name="host">URL</param>        /// <param name="model">用户名</param>        /// <param name="mapCtrl">地图控件</param>        public bool LoadServerToMap(string host, string serviceName, IMapControl3 mapCtrl)        {            List<IAGSServerObjectName> SGSList = GetUserConnectAGS(host);            string name = SGSList[0].Name;            string type = SGSList[0].Type;            string url = SGSList[0].URL;            if (SGSList == null || SGSList.Count <= 0) return false;            IMapServerLayer pMapServerLayer = new MapServerLayerClass();            foreach(IAGSServerObjectName objName in SGSList)            {                if (objName.Name.ToLower().Equals(serviceName.ToLower()) && objName.Type.Equals(ConstHelper.ServiceType))                {                    IName pName = (IName)objName;                    IAGSServerObject pServerObject = (IAGSServerObject)pName.Open();                    IMapServer pMapServer = (IMapServer)pServerObject;                    pMapServerLayer.ServerConnect(objName, pMapServer.DefaultMapName);                    mapCtrl.AddLayer(pMapServerLayer as ILayer);                    mapCtrl.Refresh();                    return true;                }            }            return false;        }        /// <summary>        /// 获取用户连接AGS对象        /// </summary>        /// <param name="host"></param>        /// <param name="model"></param>        /// <returns></returns>        public List<IAGSServerObjectName> GetUserConnectAGS(string host)        {            List<IAGSServerObjectName> AGSList = new List<IAGSServerObjectName>();            IPropertySet propertySet = new PropertySetClass();            propertySet.SetProperty("URL", host);            propertySet.SetProperty("USER", string.Empty);            propertySet.SetProperty("PASSWORD", string.Empty);            propertySet.SetProperty("CONNECTIONMODE", esriAGSConnectionMode.esriAGSConnectionModeConsumer);            IAGSServerConnectionName3 pConnectName = new AGSServerConnectionNameClass() as IAGSServerConnectionName3;            pConnectName.ConnectionProperties = propertySet;            IAGSServerConnection pConnection = ((IName)pConnectName).Open() as IAGSServerConnection;            IAGSEnumServerObjectName pServerObjectNames = pConnection.ServerObjectNames;            pServerObjectNames.Reset();            IAGSServerObjectName agsServerObjectName = pServerObjectNames.Next();            while (agsServerObjectName != null)            {                string name = agsServerObjectName.Name;                string type = agsServerObjectName.Type;                string url = agsServerObjectName.URL;                AGSList.Add(agsServerObjectName);                agsServerObjectName = pServerObjectNames.Next();            }            return AGSList;        }
//调用:URL,服务名string host = ServiceHelper.RemoveMapServer(serviceModel.T_URL);            bool result = serviceManagerHelper.LoadServerToMap(host, serviceModel.T_Name, (m_Application as IFramework).MapControl);
0 0
原创粉丝点击