Programmatic Publication of ArcGIS Map and Image Services

Automating Service Deployment in ArcGIS Server

Administrators often need to deploy map and image services dynamical without manual intervention through the Manager interface. Using the ArcGIS Web ADF framework, developers can automate the creation, configuration, and startup of server object configurations. The following approach demonstrates how to establish a server connection, define service properties, and publish both MapServer and ImageServer instances using C#.

Establishing Server Connectivity

Before publishing any service, a secure connection to the ArcGIS Server container must be established. This requires valid credentials and the host name of the server. The connection object provides access to the administration proxy, which manages service configurations.

Publishing a MapServer Service

To publish a map service, the configuration object must be initialized with the specific type "MapServer". Key properties include the path to the map document (MXD), output directories for cached images, and performance constraints such as instance pooling and recycling policies. REST capabilities should also be enabled to allow web clients to consume the service.

public class GisServiceManager
{
    private AGSServerConnection _serverConnection;
    private string _hostName;
    private string _username;
    private string _password;

    public GisServiceManager(string host, string user, string pass)
    {
        _hostName = host;
        _username = user;
        _password = pass;
    }

    public bool Connect()
    {
        try
        {
            Identity credentials = new Identity(_username, _password, "");
            _serverConnection = new AGSServerConnection(_hostName, credentials);
            _serverConnection.Connect();
            return _serverConnection.IsConnected;
        }
        catch
        {
            return false;
        }
    }

    public bool DeployMapService(string mxdLocation, string serviceName)
    {
        if (_serverConnection == null || !_serverConnection.IsConnected)
            return false;

        IServerObjectAdmin adminProxy = _serverConnection.ServerObjectAdmin;
        IServerObjectConfiguration2 serviceConfig = (IServerObjectConfiguration2)adminProxy.CreateConfiguration();

        // Define basic service identity
        serviceConfig.Name = serviceName;
        serviceConfig.TypeName = "MapServer";
        serviceConfig.IsPooled = true;
        serviceConfig.MinInstances = 1;
        serviceConfig.MaxInstances = 2;
        serviceConfig.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;

        // Configure service properties
        IPropertySet configProps = serviceConfig.Properties;
        configProps.SetProperty("FilePath", mxdLocation);
        configProps.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");
        configProps.SetProperty("VirtualOutputDir", "http://" + _hostName + "/arcgisoutput");
        configProps.SetProperty("SupportedImageReturnTypes", "URL");
        configProps.SetProperty("MaxImageWidth", "2048");
        configProps.SetProperty("MaxImageHeight", "2048");
        configProps.SetProperty("MaxRecordCount", "500");
        configProps.SetProperty("IsCached", "false");
        configProps.SetProperty("ClientCachingAllowed", "true");

        // Configure recycling rules
        IPropertySet recycleSettings = serviceConfig.RecycleProperties;
        recycleSettings.SetProperty("StartTime", "00:00");
        recycleSettings.SetProperty("Interval", "3600");

        // Enable REST access
        IPropertySet infoSettings = serviceConfig.Info;
        infoSettings.SetProperty("WebEnabled", "true");
        infoSettings.SetProperty("WebCapabilities", "Map,Query,Data");

        // Commit and start
        adminProxy.AddConfiguration(serviceConfig);
        adminProxy.StartConfiguration(serviceName, "MapServer");

        return true;
    }
}

Publishing an ImageServer Service

Image services require a slightly different property set compared to map services. The primary distinction is the use of the "Path" property pointing to an image service definition rather than an MXD file. Additionally, capabilities such as "Pixels" and "Download" are specific to image services. Pooling and instance management remain similar to map services.

    public bool DeployImageService(string imageDataPath, string serviceName)
    {
        if (_serverConnection == null || !_serverConnection.IsConnected)
            return false;

        IServerObjectAdmin adminProxy = _serverConnection.ServerObjectAdmin;
        IServerObjectConfiguration2 serviceConfig = (IServerObjectConfiguration2)adminProxy.CreateConfiguration();

        // Define service identity
        serviceConfig.Name = serviceName;
        serviceConfig.TypeName = "ImageServer";
        serviceConfig.IsPooled = true;
        serviceConfig.MinInstances = 1;
        serviceConfig.MaxInstances = 2;
        serviceConfig.StartupType = esriStartupType.esriSTAutomatic;

        // Configure image specific properties
        IPropertySet configProps = serviceConfig.Properties;
        configProps.SetProperty("Path", imageDataPath);
        configProps.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");
        configProps.SetProperty("VirtualOutputDir", "http://" + _hostName + "/arcgisoutput");
        configProps.SetProperty("SupportedImageReturnTypes", "URL");
        
        // Optional image processing settings
        // configProps.SetProperty("DefaultResamplingMethod", 0);
        // configProps.SetProperty("AllowedCompressions", "None,JPEG,LZ77");

        // Enable REST access with image capabilities
        IPropertySet infoSettings = serviceConfig.Info;
        infoSettings.SetProperty("WebEnabled", "true");
        infoSettings.SetProperty("WebCapabilities", "Image,Catalog,Metadata,Download,Pixels");

        // Commit and start
        adminProxy.AddConfiguration(serviceConfig);
        adminProxy.StartConfiguration(serviceName, "ImageServer");

        return true;
    }
}

When implementing these methods, ensure that the output directories specified in the properties exist on the server file system and have apppropriate write permissions for the ArcGIS Server account. The virtual directory must also be correctly configured in IIS to serve the generated map images.

Tags: ArcGIS-Server c-sharp MapServer ImageServer GIS-Automation

Posted on Mon, 18 May 2026 02:00:35 +0000 by dsainteclaire