By Daniel Du
In this post, we discuss site service and resource service. As we talked in part 2, there are 7 services in MapGuide Web Extension API. Before a page can use a service, it must open a site connection and create an instance of the necessary service type. All other 6 services are created by site service from a site connection. You have to initialize web tier in every page with following code snippet:
MapGuideApi.MgInitializeWebTier(“webconfig.ini”)
webconfig.ini file is text file used to perform basic initialization when a session starts, it is read by MgInitializeWebTier(). It contains parameters required to connect to the site server: IP address, port numbers, map agent requests customization, e.g. pause time between successive request, passwords for OGC (WMS & WFS) requests and etc. The values set in this file affect the performance of map server. In most cases, no need to change. If you have to, please check out this document.
An Infrastructure Map Server repository is a database that stores and manages the data for the site. The repository stores all data except data that is stored in external databases. Data stored in a repository is a resource. A resource can be persistent resource or temporary resource. Persistent resource that is available to all users is stored in the Library repository.In addition, each session has its own repository, which stores the run-time map state. It can also be used to store other data, like temporary layers that apply only to an individual session. For example, a temporary layer might be used to overlay map symbols indicating places of interest.
Resource service is used to manipulate these resources with API. To use a resource service, web page must open a site connection and create an instance of a resource service:
MgUserInformation userInfo = new MgUserInformation(sessionID);
siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo);
MgResourceService resourceService = (MgResourceService)siteConnection
.CreateService(MgServiceType.ResourceService);
Here are some commonly used methods of resource service, please find the complete method list from the AIMS API Reference.
MgResourceService::EnumerateResources
MgResourceService::GetResourceContent
MgResourceService::SetResource
With these simple APIs, you can create very useful/powerful applications as long as you have deep understanding of the resource content, in most case they are xml. If you are not familiar with resource and resource service, please view the chapter 3 of AIMS API training materials first. The exercise code sample solution 3 can be downloaded here. After that, you may want to check out this intelligence landing page, it is a good example of usage of resource service. Please look at the source code, I believe you will find it very interesting.