If your Web application or Web service does not make use of a MapServer, GeocodeServer, GeodataServer, GPServer or GlobeServer object for its functionality, you can use empty server contexts for the application or Web service to do its 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.
In some cases, the creation of an object may itself be expensive. A good example of this is a connection to a geodatabase workspace. Making 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 started 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 make use of a pooled workspace connection, such that a small number of connections are made to the database once and shared across invocations of the Web service. One method of doing this is to use a pooled GeodataServer which is configured to connect to the workspace to which your Web service needs to connect. When the instances of the GeodataServer are created to populate the object pool, each will make and hold on to a connection to the workspace. Your Web service can get a reference to one of the pooled instances of the GeodataServer, 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.
Below is an ASP.NET example of how you can use a pooled GeodataServer to get a workspace connection it:
[WebMethod] public string
PooledWSExample()
{
// connect to the GIS server
string m_host = "padisha";
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";
}
<WebMethod()> _
Public Function PooledWSExample() As String
' connect to the GIS server
Dim m_host As String = "padisha"
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, you should consider this method of pooling those workspace connections.