美文网首页
arcgisengine 连接服务

arcgisengine 连接服务

作者: A_slow_sparrow | 来源:发表于2022-05-25 15:55 被阅读0次
 /// <summary>
        /// 连接地图服务
        /// </summary>
        /// <param name="pHostOrUrl"></param>
        /// <param name="pServiceName"></param>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <param name="pIsLAN">是否有访问权限默认为没有true</param>
        /// <returns></returns>
        public IMapServer GetMapServer(string pHostOrUrl, string pServiceName, string userName = "", string pwd = "", bool pIsLAN = true)
        {
            IPropertySet pPropertySet = new PropertySetClass();
            IMapServer pMapServer = null;
            try
            {
                if (string.IsNullOrEmpty(userName)) pIsLAN = true;
                if (pIsLAN)
                    pPropertySet.SetProperty("machine", pHostOrUrl);
                else
                {
                    pPropertySet.SetProperty("url", pHostOrUrl);
                    pPropertySet.SetProperty("user", userName);
                    pPropertySet.SetProperty("password", pwd);
                }
                Type factoryType = Type.GetTypeFromProgID("esriGISClient.AGSServerConnectionFactory");
                IAGSServerConnectionFactory pFactory = (IAGSServerConnectionFactory)Activator.CreateInstance(factoryType);
                IAGSServerConnection pConnection = pFactory.Open(pPropertySet, 0);
                IAGSEnumServerObjectName pServerObjectNames = pConnection.ServerObjectNames;
                IAGSServerObjectName ServerObjectName = pServerObjectNames.Next();

                while (ServerObjectName != null)
                {
                    if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) &&
                        (ServerObjectName.Type == "MapServer"))
                    {
                        break;
                    }
                    ServerObjectName = pServerObjectNames.Next();
                }

                if (ServerObjectName == null)
                {

                    return null;
                }
                IName pName = ServerObjectName as IName;
                //访问地图服务
                IAGSServerObject pServerObject = pName.Open() as IAGSServerObject;
                pMapServer = pServerObject as IMapServer;
            }
            catch (Exception ex)
            {
                throw new Exception("打开MapServer异常:" + ex.Message + "!\r\n请确认MapServer服务是否有访问权限,如有请配置相应权限后重试。");
            }

            return pMapServer;
        }

相关文章

网友评论

      本文标题:arcgisengine 连接服务

      本文链接:https://www.haomeiwen.com/subject/blneprtx.html