This document is archived and information here might be outdated.  Recommended version.

How to connect to an image service (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with image and raster data > Working with image services and WCS services > How to connect to an image service

How to connect to an image service

This topic shows how to connect to an image service.

Connecting to an image service

The following code shows how to open an ArcGIS Server connection, search the service, and return the requested image server object:
public static IImageServer GetImageServer(string agsUrl, string serviceName)
    IImageServer imageServer=null;

    //Set connection propertyset. sample URL: http://host:port/arcgis/services.
    IPropertySet propertySet=new PropertySetClass();
    propertySet.SetProperty("url", agsUrl);

    //Open an AGS connection.
    Type factoryType=Type.GetTypeFromProgID(
    IAGSServerConnectionFactory agsFactory=(IAGSServerConnectionFactory)
    IAGSServerConnection agsConnection=agsFactory.Open(propertySet, 0);

    //Get the image server.
    IAGSEnumServerObjectName agsServerObjectNames=agsConnection.ServerObjectNames;
    IAGSServerObjectName agsServerObjectName=agsServerObjectNames.Next();
    while (agsServerObjectName != null)
        if ((agsServerObjectName.Name.ToLower() == serviceName.ToLower()) && 
            (agsServerObjectName.Type == "ImageServer"))
            IName pName=(IName)agsServerObjectName;
            IAGSServerObject agsServerObject=(IAGSServerObject)pName.Open();

    //Return the image server object.
    return imageServer;
Public Shared Function GetImageServer(ByVal agsUrl As String, ByVal serviceName As String) As IImageServer
Dim imageServer As IImageServer=Nothing

'Set connection propertyset. sample URL: http://host:port/arcgis/services.
Dim propSet As IPropertySet=New PropertySet()
propSet.SetProperty("url", agsUrl)

'Open an AGS connection.
Dim factoryType As Type=Type.GetTypeFromProgID("esriGISClient.AGSServerConnectionFactory")
Dim agsFactory As IAGSServerConnectionFactory=Activator.CreateInstance(factoryType)
Dim agsConnection As IAGSServerConnection=agsFactory.Open(propSet, 0)

'Get the image server.
Dim agsServerObjectNames As IAGSEnumServerObjectName=agsConnection.ServerObjectNames
Dim agsServerObjectName As IAGSServerObjectName=agsServerObjectNames.Next()
While (Not agsServerObjectName Is Nothing)
    If ((agsServerObjectName.Name.ToLower()=serviceName.ToLower()) And (agsServerObjectName.Type="ImageServer")) Then
        Dim pName As IName=CType(agsServerObjectName, IName)
        Dim agsServerObject As IAGSServerObject=CType(pName.Open(), IAGSServerObject)
        imageServer=CType(agsServerObject, IImageServer)
        Exit While
    End If
End While

'Return the image server object.
Return imageServer
End Function

To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Basic ArcGIS Desktop Basic
Engine Developer Kit Engine