How to connect to ArcGIS for Server with the SOM


Summary
This topic demonstrates how to connect to ArcGIS for Server via the server object manager (SOM). You must define an identity (user account) present in the agsusers or agsadmin groups on the SOM machine. Once connected, you can access existing services as server objects and work with them via server context. Server object types include, MapServer, GeocodeServer, GeometryServer, GeodataServer, ImageServer, GlobeServer, GPServer, and an empty server context.

Connecting to ArcGIS for Server with the SOM

Do the following steps:
  1. Set up an application with the Web Application Developer Framework (ADF) and ArcGIS for Server libraries using the sample description as a guide.
  2. Set the username, password, and domain variables to a user account in the agsuser or agsadmin groups on the SOM. Define the servername variable to be the machine on which the SOM is running.
  3. Set the serverobjectname to the name of an ArcGIS for Server map service.

    See the following code example:
[C#]
// Using the ArcGIS Connection library.
ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity(userName, password,
    domain);
ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsServerConnection;
agsServerConnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection
    (serverName, identity);
agsServerConnection.Connect();

// Using the ArcGIS for Server API.
ESRI.ArcGIS.Server.IServerObjectManager serverObjectManager =
    agsServerConnection.ServerObjectManager;
string serverType = "MapServer";
ESRI.ArcGIS.Server.IServerContext serverContext =
    serverObjectManager.CreateServerContext(serverObjectName, serverType);

// If pooled, release context per request. If non-pooled, release context per session.
serverContext.ReleaseContext();
[VB.NET]
' Using the ArcGIS Connection library.
Dim identity As ESRI.ArcGIS.ADF.Identity = New ESRI.ArcGIS.ADF.Identity(userName, password, domain)
Dim agsServerConnection As ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection
agsServerConnection = New ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(serverName, identity)
agsServerConnection.Connect()

' Using the ArcGIS for Server API.
Dim serverObjectManager As ESRI.ArcGIS.Server.IServerObjectManager = agsServerConnection.ServerObjectManager
Dim serverType As String = "MapServer"
Dim serverContext As ESRI.ArcGIS.Server.IServerContext = serverObjectManager.CreateServerContext(serverObjectName, serverType)

' If pooled, release context per request. If non-pooled, release context per session.
serverContext.ReleaseContext()