ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / ServiceConnectionProperties Class / URL Property
Example

In This Topic
    URL Property (ServiceConnectionProperties)
    In This Topic
    The service URL.
    Syntax
    Public ReadOnly Property URL As Uri
    public Uri URL {get;}
    Example
    Get the Data Connection Properties from a Feature Service
    {
      await QueuedTask.Run(() =>
      {
        Layer selectedLayer = MapView.Active.GetSelectedLayers()[0];
    
        if (selectedLayer is FeatureLayer)
        {
          FeatureLayer featureLayer = selectedLayer as FeatureLayer;
    
          using (Table table = featureLayer.GetTable())
          using (Datastore datastore = table.GetDatastore())
          {
            ServiceConnectionProperties serviceConnectionProperties = datastore.GetConnector() as ServiceConnectionProperties;
    
            if (serviceConnectionProperties == null)
              return;
    
            Uri url = serviceConnectionProperties.URL;      // Will be the URL to the Feature Service.
            string user = serviceConnectionProperties.User;     // The username property will only be
                                                                // populated for feature service hosted
                                                                // on non-federated ArcGIS Server.
            string password = serviceConnectionProperties.Password; // Will always be empty.
          }
        }
      });
    }
    Connect to an AGS Service using ServiceConnectionProperties
    {
        //Connect to the AGS service. Note: the connection will persist for the
        //duration of the Pro session.
        var serverUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services";
    
        var username = "user1";
        var password = "user1";
    
        //at any point before creating a layer, first make a connection to the server
        //if one has not been already established for the current session
        var uri = new Uri(serverUrl);
        var props = new ServiceConnectionProperties(uri)
        {
            User = username
        };
        //It is preferred that you use the Windows Credential Manager to store the password
    
        //However, it can be set as clear text if you so choose
        props.Password = password; //not recommended
    
    
        //Establish a connection to the server at any point in time _before_
        //creating a layer from a service on the server
        //Note: Needs QueuedTask to run
        var gdb = new Geodatabase(props);
        gdb.Dispose();//you do not need the geodatabase object after you have connected.
    
        //later in the session, as needed...create a layer from one of the services
        //on the server
        var serviceUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/MapServer";
        var lc = new LayerCreationParams(new Uri(serviceUrl));
        //Note: Needs QueuedTask to run
        LayerFactory.Instance.CreateLayer<MapImageLayer>(lc, map);
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also