ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Desktop.Catalog Namespace / ServerConnectionProjectItem Class
Members Example

In This Topic
    ServerConnectionProjectItem Class
    In This Topic
    Represents a server connection project item.
    Object Model
    ServerConnectionProjectItem ClassProjectItemInfo ClassCIMProjectServerConnection ClassTimeInstant Class
    Syntax
    public sealed class ServerConnectionProjectItem : ArcGIS.Desktop.Internal.Catalog.ProjectItemInfoCrawl, ArcGIS.Desktop.Core.IMetadata, ArcGIS.Desktop.Core.IProjectItem, ArcGIS.Desktop.Core.IProjectMultiItem, System.ComponentModel.INotifyPropertyChanged  
    Public NotInheritable Class ServerConnectionProjectItem 
       Inherits ArcGIS.Desktop.Internal.Catalog.ProjectItemInfoCrawl
       Implements ArcGIS.Desktop.Core.IMetadata, ArcGIS.Desktop.Core.IProjectItem, ArcGIS.Desktop.Core.IProjectMultiItem, System.ComponentModel.INotifyPropertyChanged 
    Remarks

    A server connection project item is a connection to an ArcGIS Server site, an OGC WMS service, or an OGC WMTS service that has been added to the current project. New server connections cannot be created, but an existing .ags, .wms, or .wmts file containing connection information can be added to a project.

    Example
    Get ServerConnectionProjectItems
    /// Get all the server connections in a project
    IEnumerable<ServerConnectionProjectItem> projectServers = Project.Current.GetItems<ServerConnectionProjectItem>();
    
    Get all ServerConnectionProjectItems
    IEnumerable<ServerConnectionProjectItem> newServerConnections = null;
    newServerConnections = project.GetItems<ServerConnectionProjectItem>();
    foreach (var serverItem in newServerConnections)
    {
      //Do Something with the server connection.
    }
    Get a specific ServerConnectionProjectItem
    ServerConnectionProjectItem serverProjItem = Project.Current.GetItems<ServerConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myServer"));
    Connect to an AGS Service using a .ags File
    //This workflow would work for 
          var agsFilePath = @"C:\Data\ServerConnectionFiles\AcmeSampleService.ags";
    
          //ServerConnectionProjectItem supports .ags, .wms, .wmts, .wfs, and .wcs files
          var server_conn_item = ItemFactory.Instance.Create(agsFilePath) 
      as ArcGIS.Desktop.Catalog.ServerConnectionProjectItem;
          
          //Get the server connection - passwords are never returned
          var serverConnection = server_conn_item.ServerConnection as CIMProjectServerConnection;
    
    //Add to an AGS service connection
    var service_connection = new CIMAGSServiceConnection()
    {
      URL = "URL to the AGS _service_ on the AGS _server_",
      ServerConnection = serverConnection
    };
    
          // Add a new layer to the map
          var layerParams = new LayerCreationParams(service_connection);
          layerParams.MapMemberPosition = MapMemberPosition.AddToBottom;
          var map = MapView.Active.Map;
          await QueuedTask.Run(() =>
          {
              var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, map);
          });
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Core.Item
                      ArcGIS.Desktop.Catalog.ServerConnectionProjectItem

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also