ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.CIM Namespace / CIMAGSServiceConnection Class / ServerConnection Property
Example

In This Topic
    ServerConnection Property (CIMAGSServiceConnection)
    In This Topic
    Gets or sets the server connection.
    Syntax
    Public Property ServerConnection As CIMServerConnection
    public CIMServerConnection ServerConnection {get; set;}
    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;
        //Note: Needs QueuedTask to run
        var layerCreated = LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, map);
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also