示例#1
0
        protected override void OnClick()
        {
            IMxDocument pmxdoc    = (IMxDocument)ArcMap.Application.Document;
            IMap        pmap      = pmxdoc.FocusMap;
            IGxDialog   pGxDialog = new GxDialog();

            pGxDialog.Title = "Browse Data";
            //pGxDialog.set_StartingLocation("C:\\Temp");
            pGxDialog.set_StartingLocation("GIS Servers");
            IEnumGxObject pEnumGx;

            if (!pGxDialog.DoModalOpen(0, out pEnumGx))
            {
                return;  // Exit if user press Cancel
            }
            IGxObject                pgxobject               = pEnumGx.Next();
            IGxAGSObject             gxAGSObject             = pgxobject as IGxAGSObject;
            IAGSServerObjectName     agsServerObjectName     = gxAGSObject.AGSServerObjectName;
            IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
            IPropertySet             propertySet             = agsServerConnectionName.ConnectionProperties;
            //create a new ArcGIS Server connection factory
            IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2) new AGSServerConnectionFactory();
            IAGSServerConnection         agsServerConnection         = agsServerConnectionFactory2.Open(propertySet, 0);
            //get an enum of all server object names from the server (GIS services, i.e.)
            IAGSEnumServerObjectName soNames        = agsServerConnection.ServerObjectNames;
            IAGSServerObjectName3    soName         = (IAGSServerObjectName3)soNames.Next();
            ILayerFactory            msLayerFactory = new MapServerLayerFactory();
            IEnumLayer      enumLyrs       = msLayerFactory.Create(soName);
            IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();

            pmap.AddLayer((ILayer)mapServerLayer);

            ArcMap.Application.CurrentTool = null;
        }
示例#2
0
        private void btnGetAllResource_Click(object sender, EventArgs e)
        {
            this.ResourcescheckedListBox.Items.Clear();
            IAGSServerConnectionFactory factory        = new AGSServerConnectionFactoryClass();
            IPropertySet         pConnectionProperties = this.method_5();
            IAGSServerConnection connection            = null;

            try
            {
                connection = factory.Open(pConnectionProperties, 0);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
                return;
            }
            IAGSEnumServerObjectName serverObjectNames = connection.ServerObjectNames;

            serverObjectNames.Reset();
            for (IAGSServerObjectName name2 = serverObjectNames.Next(); name2 != null; name2 = serverObjectNames.Next())
            {
                this.ilist_0.Add(name2);
                this.ResourcescheckedListBox.Items.Add(new Class7(name2));
            }
            connection = null;
            factory    = null;
        }
示例#3
0
        /// <summary>
        /// 获取ArcGISServer服务图层
        /// </summary>
        /// <param name="serverUrl"></param>服务器地址
        /// <param name="mapservername"></param>地图服务名称
        /// <param name="isLan"></param>地图服务是局域网内还是互联网上的
        /// <returns></returns>
        public ILayer GetARGServerLyr(String serverUrl, String mapservername, bool isLan)
        {
            ILayer lyr = null;

            //获得服务对象名称
            try
            {
                IAGSServerObjectName pServerObjectName = GetAGSMapServer(serverUrl, mapservername, isLan);//获取地图
                IName pName = (IName)pServerObjectName;
                //访问地图服务
                IAGSServerObject pServerObject = (IAGSServerObject)pName.Open();
                IMapServer       pMapServer    = (IMapServer)pServerObject;
                mapserver = pMapServer;//获取地图服务对象

                IMapServerLayer pMapServerLayer = new MapServerLayer() as IMapServerLayer;
                //连接地图服务
                pMapServerLayer.ServerConnect(pServerObjectName, pMapServer.DefaultMapName);
                //添加数据图层
                lyr = pMapServerLayer as ILayer;
            }
            catch (Exception ex)
            {
                MessageBox.Show("服务器配置信息错误,请到“系统管理-系统配置”设置", "连接失败");
            }

            return(lyr);
        }
示例#4
0
        internal static string GetNameFromAGSLayer(ILayer layer)
        {
            IAGSServerObjectName serverObjectName = GetAGSServerObjectName(layer);

            if (serverObjectName == null)
            {
                return("!Error - AGS Server Object Name Not Found");
            }
            return(serverObjectName.Name);
        }
示例#5
0
        /// <summary>
        /// 获取ArcGIS Server发布的地图服务图层
        /// </summary>
        /// <param name="serviceUrl">服务地址,例:http://services.arcgisonline.com/ArcGIS/services </param>
        /// <param name="serviceName">服务名称,例:ESRI_Imagery_World_2D</param>
        /// <param name="isLAN">是否局域网(Local Area Network)</param>
        /// <returns></returns>
        public ILayer GetServerLayer(string serviceUrl, string serviceName, bool isLAN = false)
        {
            IAGSServerObjectName serverObjectName = GetServerObjectName(serviceUrl, serviceName, isLAN);
            IName            iName          = (IName)serverObjectName;
            IAGSServerObject serverObject   = (IAGSServerObject)iName.Open();
            IMapServer       mapServer      = (IMapServer)serverObject;
            IMapServerLayer  mapServerLayer = new MapServerLayerClass();

            //连接地图服务,第一个参数为地图服务名称,第二个参数为数据框架名称(the name of a data frame)
            mapServerLayer.ServerConnect(serverObjectName, mapServer.DefaultMapName);
            return((ILayer)mapServerLayer);
        }
示例#6
0
        private void method_7()
        {
            this.ResourcescheckedListBox.Items.Clear();
            IAGSServerConnection     connection        = (this.iagsserverConnectionName_0 as IName).Open() as IAGSServerConnection;
            IAGSEnumServerObjectName serverObjectNames = connection.ServerObjectNames;

            serverObjectNames.Reset();
            for (IAGSServerObjectName name2 = serverObjectNames.Next(); name2 != null; name2 = serverObjectNames.Next())
            {
                string name = name2.Name;
                this.ResourcescheckedListBox.Items.Add(name, this.method_6(name));
            }
            connection = null;
        }
        private IMapServer method_0(string string_3)
        {
            IAGSEnumServerObjectName serverObjectNames = this.iagsserverConnection_0.ServerObjectNames;
            IAGSServerObjectName     name2             = null;

            while ((name2 = serverObjectNames.Next()) != null)
            {
                if (name2.Name == string_3)
                {
                    break;
                }
            }
            IName name3 = name2 as IName;

            return(name3.Open() as IMapServer);
        }
示例#8
0
        public IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
        {
            //设置连接属性
            IPropertySet pPropertySet = new PropertySetClass();

            if (pIsLAN)
            {
                pPropertySet.SetProperty("machine", pHostOrUrl);
            }
            else
            {
                pPropertySet.SetProperty("url", pHostOrUrl);
            }

            //打开连接

            IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory();
            //Type factoryType = Type.GetTypeFromProgID(
            //    "esriGISClient.AGSServerConnectionFactory");
            //IAGSServerConnectionFactory agsFactory = (IAGSServerConnectionFactory)
            //    Activator.CreateInstance(factoryType);
            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);
        }
示例#9
0
        /// <summary>
        /// 获取ArcGisServer地图服务标识,连接服务器
        /// </summary>
        /// <param name="pHostOrUrl"></param>服务器主机URL
        /// <param name="pServiceName"></param>服务名称
        /// <param name="pIsLAN"></param>主机是否是在局域网或者是互联网
        /// <returns></returns>
        private IAGSServerObjectName GetAGSMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
        {
            //设置连接属性
            IPropertySet pPropertySet = new PropertySet();

            if (pIsLAN)
            {
                pPropertySet.SetProperty("machine", pHostOrUrl);
            }
            else
            {
                pPropertySet.SetProperty("url", pHostOrUrl);
            }

            IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory();
            IAGSServerConnection        agsConn  = pFactory.Open(pPropertySet, 0);

            //打开获取服务器
            IAGSEnumServerObjectName pServerObjectNames = agsConn.ServerObjectNames;

            //获取服务器上所有服务的标识属性,即服务标识集合
            pServerObjectNames.Reset();
            //使指针指向服务开头
            IAGSServerObjectName ServerObjectName = null;

            //获取服务标识
            while ((ServerObjectName = pServerObjectNames.Next()) != null)
            {
                if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) &&
                    (ServerObjectName.Type == "MapServer"))
                {//判断获取所需服务
                    break;
                }
            }
            //返回对象
            return(ServerObjectName);//返回服务标识
        }
示例#10
0
        /// <summary>
        /// Add AGS Map Layer
        /// </summary>
        /// <param name="inUserName"></param>
        /// <param name="inPassword"></param>
        /// <param name="inName"></param>
        /// <param name="inMapUrl"></param>
        internal void AddAGSLayer(string inUserName, string inPassword, string inName, string inMapUrl)
        {
            IAGSServerConnectionName2 agsServerConnectionName = (IAGSServerConnectionName2) new AGSServerConnectionName();

            // http://localhost/ArcGIS/rest/services/Map1/MapServer
            // Convert to http://localhost/ArcGis/Services
            // and http://localgsot/ArcGIS/Map1/MapServer

            string servicecatalog = inMapUrl.Substring(0, inMapUrl.IndexOf("/REST/SERVICES", StringComparison.CurrentCultureIgnoreCase)) + "/Services";
            string mapserviceurl  = ReplaceEx(inMapUrl, "/REST/", "/", StringComparison.InvariantCultureIgnoreCase);
            string mapservice     = "";
            Regex  rMapServerRest = new Regex("^(?i:.*/REST/SERVICES/(?<mapname>.*)/MAPSERVER.*)$");
            Match  m = rMapServerRest.Match(inMapUrl);

            if (m.Success)
            {
                mapservice = m.Groups["mapname"].Value;
            }


            //Create a property set of connection details
            IPropertySet props = new PropertySet();

            props.SetProperty("url", servicecatalog);
            if (inUserName != null)
            {
                props.SetProperty("user", inUserName);
                props.SetProperty("password", inPassword);
                props.SetProperty("hideuserproperty", false);
                props.SetProperty("anonymous", false);
            }
            IAGSServerObjectName2 agsServerObjectName = (IAGSServerObjectName2) new AGSServerObjectName();

            IAGSServerConnectionFactory AGSConnectionFactory = new AGSServerConnectionFactory();

            IAGSServerConnection     AGSConnection = AGSConnectionFactory.Open(props, 0);
            IAGSEnumServerObjectName enumSOName    = null;



            enumSOName = AGSConnection.ServerObjectNames;
            IAGSServerObjectName SOName = null;

            SOName = enumSOName.Next();
            while (SOName != null)
            {
                System.Diagnostics.Debug.WriteLine(SOName.Name + ": " + SOName.Type);
                if (SOName.Name.Equals(mapservice, StringComparison.InvariantCultureIgnoreCase) && SOName.Type == "MapServer")
                {
                    //create the layer object
                    IMapServerGroupLayer mapServerLayer = new MapServerLayerClass();
                    IName      mapServerConnectionName  = (IName)SOName;
                    IDataLayer dataLayer = (IDataLayer)mapServerLayer;
                    //try to connect
                    try
                    {
                        dataLayer.Connect(mapServerConnectionName);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Could not connect to URL", ex);
                    }

                    //create the layer name
                    ILayer layer;

                    layer         = (ILayer)mapServerLayer;
                    layer.Visible = true;
                    layer.Name    = inName;

                    //return the layer
                    ArcMap.Document.AddLayer(layer);
                    break;
                }
                SOName = enumSOName.Next();
            }
        }
示例#11
0
 public Class5(IAGSServerObjectName iagsserverObjectName_1)
 {
     this.iagsserverObjectName_0 = iagsserverObjectName_1;
 }
示例#12
0
        /// <summary>
        /// Parse ArcGIS MapServer Service
        /// </summary>
        /// <param name="urlAGS"></param>
        public void OpenAGS(string urlAGS)
        {
            try
            {
                ///Parse the url for MapServer -- get the service url and the service name
                string   strUrl      = urlAGS;
                string[] strUrlParts = strUrl.Split('/');
                string   strUrlSvr   = null;
                string   strSvrName  = null;

                for (int i = 0; i < strUrlParts.Length; i++)
                {
                    if (strUrlParts[i] == "services")
                    {
                        strUrlSvr = string.Join("/", strUrlParts.Take(i + 1).ToArray());

                        for (int j = i + 1; j < strUrlParts.Length - 1; j++)
                        {
                            if (strSvrName != null)
                            {
                                strSvrName += "/";
                            }
                            strSvrName += strUrlParts[j];
                        }
                        break;
                    }
                }


                ///Set up ArcGIS Service connection factory, which includes the list of services
                IAGSServerConnectionFactory pAGSSvrConnFactory = new AGSServerConnectionFactoryClass();
                IPropertySet pPropSet = new PropertySetClass();
                pPropSet.SetProperty("URL", strUrlSvr);
                IAGSServerConnection pAGSSvrConn = pAGSSvrConnFactory.Open(pPropSet, 0);

                ///Get the list of services
                IAGSEnumServerObjectName pEnumSOName = pAGSSvrConn.ServerObjectNames;
                IAGSServerObjectName     pAGSSOName  = pEnumSOName.Next();

                ///Get the specific service with the service name
                while (pAGSSOName != null)
                {
                    //Debug.WriteLine(pAGSSOName.Name + ":" + pAGSSOName.Type);

                    if (pAGSSOName.Name == strSvrName && pAGSSOName.Type == "MapServer")
                    {
                        break;
                    }

                    pAGSSOName = pEnumSOName.Next();
                }

                ///Open the specific service
                IName      pName      = pAGSSOName as IName;
                IMapServer pMapServer = pName.Open() as IMapServer;

                IMapServerLayer pMapSvrLayer = new MapServerLayerClass();
                pMapSvrLayer.ServerConnect(pAGSSOName, pMapServer.DefaultMapName);

                ///Configure the layer before adding it to the map
                ILayer pLayer = pMapSvrLayer as ILayer;
                AddLayer(pLayer);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
        }
示例#13
0
 private void method_0()
 {
     try
     {
         if (this.AGSServerConnection != null)
         {
             IAGSEnumServerObjectName name = this.AGSServerConnection.get_ServerObjectNamesEx(this.FolderName);
             name.Reset();
             for (IAGSServerObjectName name2 = name.Next(); name2 != null; name2 = name.Next())
             {
                 IGxObject obj2;
                 bool      flag;
                 if (name2.Type.ToLower() == "mapserver")
                 {
                     obj2 = new GxAGSMap();
                     (obj2 as IGxAGSObject).AGSServerObjectName = name2;
                     flag = true;
                     if (((this.Parent as IGxAGSConnection).ConnectionMode == 0) &&
                         ((obj2 as IGxAGSObject).Status != "Started"))
                     {
                         flag = false;
                     }
                     if (flag)
                     {
                         obj2.Attach(this, this.igxCatalog_0);
                     }
                 }
                 else if (name2.Type.ToLower() == "featureserver")
                 {
                     if ((this.Parent as IGxAGSConnection).ConnectionMode == 0)
                     {
                         obj2 = new GxFeatureService();
                         (obj2 as IGxAGSObject).AGSServerObjectName = name2;
                         if ((obj2 as IGxAGSObject).Status == "Started")
                         {
                             obj2.Attach(this, this.igxCatalog_0);
                         }
                     }
                 }
                 else if (name2.Type.ToLower() == "gpserver")
                 {
                     obj2 = new GxGPServer();
                     (obj2 as IGxAGSObject).AGSServerObjectName = name2;
                     flag = true;
                     if (((this.Parent as IGxAGSConnection).ConnectionMode == 0) &&
                         ((obj2 as IGxAGSObject).Status != "Started"))
                     {
                         flag = false;
                     }
                     if (flag)
                     {
                         obj2.Attach(this, this.igxCatalog_0);
                     }
                 }
                 else if (name2.Type.ToLower() == "geometryserver")
                 {
                     if ((this.Parent as IGxAGSConnection).ConnectionMode > 0)
                     {
                         obj2 = new GxGeometryServer();
                         (obj2 as IGxAGSObject).AGSServerObjectName = name2;
                         obj2.Attach(this, this.igxCatalog_0);
                     }
                 }
                 else if (name2.Type.ToLower() == "searchserver")
                 {
                     obj2 = new GxSearchServer();
                     (obj2 as IGxAGSObject).AGSServerObjectName = name2;
                     flag = true;
                     if (((this.Parent as IGxAGSConnection).ConnectionMode == 0) &&
                         ((obj2 as IGxAGSObject).Status != "Started"))
                     {
                         flag = false;
                     }
                     if (flag)
                     {
                         obj2.Attach(this, this.igxCatalog_0);
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
         Logger.Current.Error("", exception, "");
     }
 }
示例#14
0
        internal static ConnectionStringList GetConnectionString(ILayer layer, string filepath)
        {
            ConnectionStringList connectionStrings = new ConnectionStringList();

            Trace.WriteLine("ConnectionStringList LayerName: {0})".FormatString(layer.Name));

            if (layer is IFeatureLayer)
            {
                IFeatureLayer featureLayer = layer as IFeatureLayer;

                IDataset dataset = featureLayer.FeatureClass as IDataset;

                if (dataset != null)
                {
                    object propertyNames;
                    object propertyValues;

                    dataset.Workspace.ConnectionProperties.GetAllProperties(out propertyNames, out propertyValues);

                    connectionStrings.Add(
                        string.Format(LayerConnectionString, layer.Name, MakeConnectionString(propertyNames, propertyValues), filepath));
                }
                else
                {
                    connectionStrings.Add(string.Format(LayerConnectionString, layer.Name, "No Dataset Information", filepath));
                }
            }
            else if (layer is ImageServerLayer)
            {
                IImageServerLayer  imageserverlayer  = layer as IImageServerLayer;
                IImageServerLayer2 imageserverlayer2 = layer as IImageServerLayer2;
                if (imageserverlayer != null)
                {
                    IAGSServerObject2 serverobject = (imageserverlayer.DataSource) as IAGSServerObject2;
                    if (serverobject != null)
                    {
                        IAGSServerObjectName serverobjectname = serverobject.FullName as IAGSServerObjectName;
                        if (serverobjectname != null)
                        {
                            //name, description, url
                            string s           = "{0},{1},{2}";
                            string servicename = serverobjectname.Name;
                            string serviceurl  = serverobjectname.URL;
                            string servicetype = serverobjectname.Type;

                            connectionStrings.Add(s.FormatString(
                                                      servicename,
                                                      servicetype,
                                                      serviceurl));
                        }
                    }
                    Trace.WriteLine(imageserverlayer2.ServiceProperties);
                }
            }
            else if (layer is MapServerLayer)
            {
                IMapServerLayer mapServerLayer = layer as IMapServerLayer;

                if (mapServerLayer != null)
                {
                    try
                    {
                        IAGSServerObjectName agsson;
                        string docLocation = string.Empty;
                        string mapname     = string.Empty;

                        mapServerLayer.GetConnectionInfo(out agsson, out docLocation, out mapname);
                        string s = "{0},{1},{2}";

                        connectionStrings.Add(s.FormatString(agsson.Name, agsson.Type, agsson.URL));
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.StackTrace);
                        throw;
                    }
                }
            }
            else if (layer is IGroupLayer)
            {
                ICompositeLayer compositeLayer = layer as ICompositeLayer;

                for (int i = 0; i < compositeLayer.Count; i++)
                {
                    ILayer subLayer = compositeLayer.Layer[i];

                    connectionStrings.AddRange(GetConnectionString(subLayer, filepath));
                }
            }
            else
            {
            }

            return(connectionStrings);
        }
示例#15
0
 private void method_1()
 {
     try
     {
         object    obj2;
         object    obj3;
         IGxObject obj4;
         this.ipropertySet_0.GetAllProperties(out obj2, out obj3);
         string[] strArray = (string[])obj2;
         if ((strArray.Length == 6) && (strArray[1] == "MANAGERURL"))
         {
             obj4 = new GxAddAGSObject();
             obj4.Attach(this, this.igxCatalog_0);
         }
         if (this.iagsserverConnection2_0 != null)
         {
             IEnumBSTR folders = this.iagsserverConnection2_0.GetFolders("");
             folders.Reset();
             for (string str = folders.Next(); str != null; str = folders.Next())
             {
                 IGxServersFolder folder = new GxServersFolder
                 {
                     AGSServerConnection = this.iagsserverConnection2_0,
                     FolderName          = str
                 };
                 (folder as IGxObject).Attach(this, this.igxCatalog_0);
             }
             IAGSEnumServerObjectName name = this.iagsserverConnection2_0.get_ServerObjectNamesEx("");
             name.Reset();
             for (IAGSServerObjectName name2 = name.Next(); name2 != null; name2 = name.Next())
             {
                 bool flag;
                 if (name2.Type.ToLower() == "mapserver")
                 {
                     if (this.method_0(name2.Name))
                     {
                         obj4 = new GxAGSMap();
                         (obj4 as IGxAGSObject).AGSServerObjectName = name2;
                         flag = true;
                         if ((this.ConnectionMode == 0) && ((obj4 as IGxAGSObject).Status != "Started"))
                         {
                             flag = false;
                         }
                         if (flag)
                         {
                             obj4.Attach(this, this.igxCatalog_0);
                         }
                     }
                 }
                 else if (name2.Type.ToLower() == "gpserver")
                 {
                     if (this.method_0(name2.Name))
                     {
                         obj4 = new GxGPServer();
                         (obj4 as IGxAGSObject).AGSServerObjectName = name2;
                         flag = true;
                         if ((this.ConnectionMode == 0) && ((obj4 as IGxAGSObject).Status != "Started"))
                         {
                             flag = false;
                         }
                         if (flag)
                         {
                             obj4.Attach(this, this.igxCatalog_0);
                         }
                     }
                 }
                 else if (name2.Type.ToLower() == "featureserver")
                 {
                     if (this.ConnectionMode == 0)
                     {
                         obj4 = new GxFeatureService();
                         (obj4 as IGxAGSObject).AGSServerObjectName = name2;
                         if ((obj4 as IGxAGSObject).Status == "Started")
                         {
                             obj4.Attach(this, this.igxCatalog_0);
                         }
                     }
                 }
                 else if ((name2.Type.ToLower() == "geometryserver") && (this.ConnectionMode > 0))
                 {
                     obj4 = new GxGeometryServer();
                     (obj4 as IGxAGSObject).AGSServerObjectName = name2;
                     obj4.Attach(this, this.igxCatalog_0);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
         Logger.Current.Error("", exception, "");
     }
 }
示例#16
0
        /// <summary>
        /// Adds ArcGIS layer to map
        /// </summary>
        /// <param name="ipMxDoc"></param>
        /// <param name="strServer"></param>
        /// <param name="strLayerName"></param>
        /// <param name="strSecretName"></param>
        /// <returns></returns>
        private bool addLayerAGS(IMxDocument ipMxDoc, string strServer, string strLayerName, string strSecretName)
        {
            IPropertySet2 pProps = null;
            string        pServerUrl;
            string        strServerObj;

            pServerUrl = GetAGSServiceUrl(strServer);

            // connect to the GIS server
            IAGSServerConnectionFactory pAGSServerConnectionFactory = new AGSServerConnectionFactory();

            pProps = (IPropertySet2) new PropertySet();
            pProps.SetProperty("URL", pServerUrl);

            IAGSServerConnection pAGSConnection = pAGSServerConnectionFactory.Open(pProps, 0);

            //get server objectname from url
            strServerObj = GetServerObjectName(strServer);

            // enumerate over server objects
            IAGSEnumServerObjectName pAGSSObjs = pAGSConnection.ServerObjectNames;
            IAGSServerObjectName     pAGSSObj  = pAGSSObjs.Next();

            while (pAGSSObj != null)
            {
                if (pAGSSObj.Type == "MapServer" && pAGSSObj.Name == strServerObj)
                {
                    break;
                }
                pAGSSObj = pAGSSObjs.Next();
            }


            IName            pName     = (IName)pAGSSObj;
            IAGSServerObject pAGSO     = (IAGSServerObject)pName.Open();
            IMapServer       mapServer = (IMapServer)pAGSO;


            IPropertySet prop = new PropertySetClass();

            prop.SetProperty("URL", pServerUrl);
            prop.SetProperty("Name", pAGSSObj.Name);

            //Create new layer
            IMapServerLayer pMSLayer = (IMapServerLayer) new MapServerLayer();

            pMSLayer.ServerConnect(pAGSSObj, mapServer.DefaultMapName);

            if (!isMapServerAdded(strServer))
            {
                setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName);
                IMap ipMap = ipMxDoc.FocusMap;
                ipMap.AddLayer((ILayer)pMSLayer);
                logger.writeLog(StringResources.AddAGSLayer + strSecretName);
            }
            else
            {
                // set visibility
                setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName);
            }

            //add to the service list
            string strItem = EncodeServiceList(strServer, strLayerName, strSecretName);

            // m_pLogger.Msg "adding to service list : " & strItem
            colServiceList.Add(strItem);

            //set flag
            logger.writeLog("strServer = " + strServer + " strServer & strLayerName = " + strServer + strLayerName);
            return(true);
        }