How to work with the ArcGIS for Server ArcObjects API


Summary
This topic shows how to access ArcGIS for Server locally, work with the ArcObjects application programming interface (API) via a MapResource, and iterate through the layers in a map server object.

Working with the ArcGIS for Server ArcObjects API

Local access to ArcGIS for Server means connecting to a service via the SOM (server object manager). The ArcGIS for Server data source implementation in the Web Application Developer Framework (ADF) uses the ArcGIS for Server Simple Object Access Protocol (SOAP) API for Local and Internet connections. As a result, the Web ADF uses the SOAP API to maintain the state on the client by working with Value objects and service proxies instead of managing references to remote Component Object Model (COM) objects (as is the case in the single-source Web ADF included in ArcGIS Server 9.0 and 9.1).
If the data source for a MapResource uses an ArcGIS for Server Local connection, an ArcGIS for Server Local MapResource class, named MapResourceLocal, provides access to server context. With access to server context, a developer can work with ArcObjects on the geographic information system (GIS) server.
When working with ArcObjects via server context, you can change server object state and utilize fine-grained ArcObjects. Changing the state of a server object can be managed in the following ways:
  • Deeply stateful—Deeply stateful changes should only be made when working with a non-pooled service. For non-pooled services, there is a one-to-one relationship between client and server object; thus, the state can be maintained across requests within the same server object context.
  • Shallowly stateful—Shallowly stateful changes can be managed when working with a pooled service. Clients working with a pool of server objects must create and release server context upon each request. As a result, the state must be maintained on the client, applied to server context before an operation, then the server object reset before releasing server context.
The Web ADF ArcGIS Server MapResource maintains the state using ArcGIS for Server SOAP Value objects included with the Web ADF (ESRI.ArcGIS.ADF.ArcGISServer). To manage state changes at the Web ADF level, update the properties of the MapDescription associated with a MapFunctionality or MapResource. For more information, see Converting between data types.
See the following code example:
[C#]
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gisFunctionality in
    Map1.GetFunctionalities())
{
    if (gisFunctionality is
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)
    {
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality
            agsMapFunctionality = 
            (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)
            gisFunctionality;
        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal
            agsMapResourceLocal = 
            (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)
            agsMapFunctionality.MapResource;

        ESRI.ArcGIS.Server.IServerContext serverContext =
            agsMapResourceLocal.ServerContextInfo.ServerContext;
        ESRI.ArcGIS.Carto.IMapServer mapServer = (ESRI.ArcGIS.Carto.IMapServer)
            serverContext.ServerObject;
        ESRI.ArcGIS.Carto.IMapServerInfo mapServerInfo = mapServer.GetServerInfo
            (mapServer.DefaultMapName);
        ESRI.ArcGIS.Carto.IMapDescription mapDescription =
            mapServerInfo.DefaultMapDescription;
        ESRI.ArcGIS.Carto.IMapLayerInfos mapLayerInfos = 
            (ESRI.ArcGIS.Carto.IMapLayerInfos)mapServerInfo.MapLayerInfos;

        for (int i = 0; i < mapLayerInfos.Count; i++)
        {
            ESRI.ArcGIS.Carto.IMapLayerInfo mapLayerInfo = 
                (ESRI.ArcGIS.Carto.IMapLayerInfo)mapLayerInfos.get_Element(i);
            ESRI.ArcGIS.Carto.ILayerDescription layerDescription = 
                (ESRI.ArcGIS.Carto.ILayerDescription)
                mapDescription.LayerDescriptions.get_Element(i);
        }
    }
}
[VB.NET]
For Each gisFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality In Map1.GetFunctionalities()
    If TypeOf gisFunctionality Is ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality Then
        Dim agsMapFunctionality As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality = CType(gisFunctionality, ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)
        
        Dim agsMapResourceLocal As ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal = CType(agsMapFunctionality.MapResource, ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)
        
        Dim serverContext As ESRI.ArcGIS.Server.IServerContext = agsMapResourceLocal.ServerContextInfo.ServerContext
        Dim mapServer As ESRI.ArcGIS.Carto.IMapServer = CType(serverContext.ServerObject, ESRI.ArcGIS.Carto.IMapServer)
        Dim mapServerInfo As ESRI.ArcGIS.Carto.IMapServerInfo = mapServer.GetServerInfo(mapServer.DefaultMapName)
        Dim mapDescription As ESRI.ArcGIS.Carto.IMapDescription = mapServerInfo.DefaultMapDescription
        Dim mapLayerInfos As ESRI.ArcGIS.Carto.IMapLayerInfos = CType(mapServerInfo.MapLayerInfos, ESRI.ArcGIS.Carto.IMapLayerInfos)
        
        Dim i As Integer = 0
        Do While i < mapLayerInfos.Count
            Dim mapLayerInfo As ESRI.ArcGIS.Carto.IMapLayerInfo = CType(mapLayerInfos.get_Element(i), ESRI.ArcGIS.Carto.IMapLayerInfo)
            Dim layerDescription As ESRI.ArcGIS.Carto.ILayerDescription = CType(mapDescription.LayerDescriptions.get_Element(i), ESRI.ArcGIS.Carto.ILayerDescription)
            i + = 1
        Loop
    End If
Next gisFunctionality






Additional Requirements
  • This topic assumes that a MapResourceManager and a Map (named Map1) are available in the current scope (for example, in the Page). The code example references the default data frame in the server object. A MapLayerInfo and LayerDescription can be retrieved for each layer.