Pooling objects with server objects


Local (DCOM) connections are only supported for ArcGIS Server versions prior to 10.1.

About pooling objects with server objects

If your Web application or Web service uses the MapServer, GeocodeServer, GeodataServer, GPServer, or GlobeServer object for its functionality, you can use empty server contexts for the application or Web service to perform its geographic information system (GIS) work. Empty server contexts are non-pooled, so all objects you need to use must be created each time you get an empty context using the CreateObject method.
Creating an object can be expensive. A good example of this is a connection to a geodatabase workspace. Creating a geodatabase workspace connection involves connecting to a database management system (DBMS) and querying various tables in the database. If each invocation of a Web service starts with connecting to a geodatabase workspace, that introduces the fixed cost of making the connection. Additionally, this puts a load on, and can impact the scalability of, the database server.
Ideally, your Web service should use a pooled workspace connection so that a small number of connections are made to the database once and are shared across invocations of the Web service. One method of doing this is to use a pooled GeodataServer that is configured to connect to the workspace to which your Web service must connect. When the instances of the GeodataServer are created to populate the object pool, each makes and holds on to a connection to the workspace. Your Web service can get a reference to one of the pooled instances of the GeodataServer and get the workspace from the server object. Once the Web service finishes executing and releases the GeodataServer, it and its database connection return to the pool for use by another invocation of the Web service.
The following code example shows how to use a pooled GeodataServer to get a workspace connection:
[C#]
[WebMethod]
public string PooledWSExample()
{
    // Connect to the GIS server.
    string m_host = "localhost";

    ESRI.ArcGIS.ADF.Identity agsID = new ESRI.ArcGIS.ADF.Identity("user", "passwd", 
        "domain");
    ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection connection = new
        ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(m_host, agsID, true);


    // Get a server context.
    IServerObjectManager som = connection.ServerObjectManager;
    IServerContext sc = som.CreateServerContext("MyGDBServer", "GeodataServer");

    // Get the workspace from the GeodataServer.
    IGeoDataServer gds = sc.ServerObject as IGeoDataServer;
    IGeoDataServerObjects gdo = gds as IGeoDataServerObjects;
    IWorkspace ws = gdo.DefaultWorkingWorkspace;

    // Do something with the workspace.

    sc.ReleaseContext();

    return "Operation complete";
}
[VB.NET]
<WebMethod()> _
           Public Function PooledWSExample() As String
    
    ' Connect to the GIS server.
    Dim m_host As String = "localhost"
    
    Dim agsID As ESRI.ArcGIS.ADF.Identity = New ESRI.ArcGIS.ADF.Identity("user", "passwd", "domain")
    Dim connection As ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection = New ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(m_host, agsID, True)
    
    ' Get a server context.
    Dim som As IServerObjectManager = connection.ServerObjectManager
    Dim sc As IServerContext = som.CreateServerContext("MyGDBServer", "GeodataServer")
    
    ' Get the workspace from the GeodataServer.
    Dim gds As IGeoDataServer = sc.ServerObject
    Dim gdo As IGeoDataServerObjects = gds
    Dim ws As IWorkspace = gdo.DefaultWorkingWorkspace
    
    ' Do something with the workspace.
    
    sc.ReleaseContext()
    
    Return "Operation complete"
End Function
If you are developing Web services that involve connecting to geodatabase workspaces, consider this method of pooling those workspace connections.