Get standalone non-spatial table in SOE

2532
4
09-05-2012 07:01 AM
SanajyJadhav
Occasional Contributor II
Hello,

I am developing REST SOE.It queries the standalone non spatial table in the map service.


I am not being able to figure out how to get reference to this ITable.I can access other feature classes but am facing problem to access this ITable.

Can anybody help me on this issue? I would appreciate it.

Thanks.
0 Kudos
4 Replies
SanajyJadhav
Occasional Contributor II
I figured it out. I pasting my code if anybody is interested.

        private ITable SetNonSpatialTable(string tableName)
        {
            try
            {
                //get map server
                IMapServer3 mapServer = (IMapServer3)serverObjectHelper.ServerObject;

                //get default map name
                string mapName = mapServer.DefaultMapName;

                //get map server info
                IMapServerInfo3 pMapSrverInfo = mapServer.GetServerInfo(mapName) as IMapServerInfo3;

                //get standalone table info collection
                IStandaloneTableInfos pStandaloneTblInfos = pMapSrverInfo.StandaloneTableInfos;

                int? tableID = null;
                //get the ID of the desired table
                for (int i = 0; i < pStandaloneTblInfos.Count; i++)
                {
                    IStandaloneTableInfo pStandaloneTblInfo = pStandaloneTblInfos.get_Element(i);

                    //if the name matches, then set table ID
                    if (pStandaloneTblInfo.Name.ToUpper() == tableName.ToUpper())
                    {
                        tableID = pStandaloneTblInfo.ID;
                    }
                }

                //get map server object
                IMapServerObjects3 pMapServerObj = serverObjectHelper.ServerObject as IMapServerObjects3;

                if (tableID != null)
                {
                    ITable pTable = pMapServerObj.get_StandaloneTable(mapName, Convert.ToInt16(tableID));
                    return pTable;
                }

                return null;
            }
            catch (Exception ex)
            {
                string errMsg = "An Error occured in the SOE method - SetNonSpatialTable - " + " " + "Error : " + ex.Message
               + "Stack Trace : " + " " + ex.StackTrace;
                logger.LogMessage(ServerLogger.msgType.error, "SetNonSpatialTable", 400, errMsg);
                return null;
            }
        }
0 Kudos
CarolineShepherd
New Contributor II
I was just wondering how I was going to achieve the same thing!

Thanks for posting the solution!

Caroline
0 Kudos
SanajyJadhav
Occasional Contributor II
You are welcome.
0 Kudos
PaulSchneider
Occasional Contributor
Used this today...

Utilized the .GetDataSource method of the IMapServerDataAccess

...
[LEFT]IMapServer3 mapServer = serverObjectHelper.ServerObject as IMapServer3;
IStandaloneTableInfos satInfos = _MapServerInfo.StandaloneTableInfos;
IStandaloneTableInfo satInfo;
string myTableName;

for (int i = 0; i < satInfos.Count; i++)
{[INDENT]satInfo = satInfos.get_Element(i);
if (myTableName.Equals(satInfo.Name, StringComparison.InvariantCultureIgnoreCase) == true)
{
[INDENT]ITable myTable = setNonSpatialTable(mapServer.DefaultMapName, i);
break;[/INDENT]}[/INDENT]}
...

private ITable setNonSpatialTable(string mapName, int tablei) 
{
[INDENT]if (tablei != null)
{
[INDENT]tablei = tablei + _MapServerInfo.MapLayerInfos.Count; //Tables listed after layers

ITable outTable = (ITable)_MapServerDataAccess.GetDataSource(mapName, tablei);
return outTable;[/INDENT]}
return null;[/INDENT]}
...[/LEFT]


Thanks!
0 Kudos