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


How to connect to an image service (ArcObjects .NET 10.4 SDK)

How to connect to an image service


Summary
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:
[C#]
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(
        "esriGISClient.AGSServerConnectionFactory");
    IAGSServerConnectionFactory agsFactory=(IAGSServerConnectionFactory)
        Activator.CreateInstance(factoryType);
    IAGSServerConnection agsConnection=agsFactory.Open(propertySet, 0);

    //Get the image server.
    IAGSEnumServerObjectName agsServerObjectNames=agsConnection.ServerObjectNames;
    agsServerObjectNames.Reset();
    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();
            imageServer=(IImageServer)agsServerObject;
            break;
        }
        agsServerObjectName=agsServerObjectNames.Next();
    }

    //Return the image server object.
    return imageServer;
}
[VB.NET]
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
agsServerObjectNames.Reset()
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
    Else
        agsServerObjectName=agsServerObjectNames.Next()
    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 for Desktop Advanced ArcGIS for Desktop Advanced
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
Engine Developer Kit Engine