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

In This Topic
    ServerConnection Property (ServerConnectionProjectItem)
    In This Topic
    Gets and sets the ServerConnection.
    Syntax
    public CIMProjectServerConnection ServerConnection {get; set;}
    Public Property ServerConnection As CIMProjectServerConnection
    Example
    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);
          });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also