Getting Attributes from an ArcGIS Server Map Service

341
0
12-04-2013 12:44 PM
BruceNielsen
Occasional Contributor III
I have a Map Service layer from ArcGIS Server that I can query using the Identify tool:[ATTACH=CONFIG]29589[/ATTACH]

I'm writing some test code to try to achieve the same thing via ArcObjects:
            Dim pMxDoc As IMxDocument = My.ArcMap.Document
            Dim pLayer As ILayer = pMxDoc.FocusMap.Layer(0) 'Map Service layer

            Dim pnt As New Point
            pnt.SpatialReference = pMxDoc.FocusMap.SpatialReference 'same as layer 0
            pnt.PutCoords(-11171129, 5523036)

            Dim pArray As IArray = CType(pLayer, IIdentify2).Identify(pnt, Nothing)
            Dim pFIO As IFeatureIdentifyObj
            For i = 0 To pArray.Count - 1
                pFIO = pArray.Element(i) 'Error occurs here
            Next


The resulting pArray has 2 objects, which corresponds with the 2 layers in the Map Service layer. But when I cast to the IFeatureIdentifyObj (as suggested in the API Reference), it throws this error:
A first chance exception of type 'System.InvalidCastException' occurred in GISserver.dll
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.IFeatureIdentifyObj'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{4E08D830-D361-11D2-8CD0-00C04F5B951E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at GISserver.Button1.OnClick() in C:\Users\documents\visual studio 2010\Projects\GISserver\GISserver\Button1.vb:line 27

Can someone tell me what is missing?
0 Kudos
0 Replies