Accessing an image service via LAN or Internet connection
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 hostOrUrl, string serviceName, bool
isLAN)
{
IImageServer imageServer = null;
//Set connection propertyset: host for LAN, url for Internet.
IPropertySet propertySet = new PropertySetClass();
if (isLAN)
propertySet.SetProperty("machine", hostOrUrl);
else
propertySet.SetProperty("url", hostOrUrl);
//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 hostOrUrl As String, ByVal serviceName As String, ByVal isLAN As Boolean) As IImageServer
Dim imageServer As IImageServer = Nothing
'Set connection propertyset: host for LAN, url for Internet.
Dim propSet As IPropertySet = New PropertySet()
If (isLAN) Then
propSet.SetProperty("machine", hostOrUrl)
Else
propSet.SetProperty("url", hostOrUrl)
End If
'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):
ESRI.ArcGIS.Carto ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)ESRI.ArcGIS.GISClient
Development licensing | Deployment licensing |
---|---|
ArcInfo | ArcInfo |
ArcEditor | ArcEditor |
ArcView | ArcView |
Engine Developer Kit | Engine Runtime |