Select to view content in your preferred language

Issue with Identify

1508
11
10-21-2010 07:06 AM
TerryGiles
Frequent Contributor
I'm working on an Identify tool that works against all layers in the map.  The code is pretty straight forward and very similar to the ESRI samples as shown below.  It works great in most cases including dynamic services with projections different than the map.
Where I'm having a problem is getting the results back for a service where security has been enabled in ArcGIS Server (using windows accounts as the store & I am in a group with access to the services).  When the Identity executes against one of these services I see 2 Requests being sent in Fiddler - the 1st returns a 401 not authorized error and the 2nd contains the results of the identify.  I believe this double request scenario is normal as it does this if I pan the map and it makes an export image request against the service - please correct me if I am wrong though.  However I never get the valid results in the ExecuteCompleted routine but the layer draws fine in the map.  What am I missing with these secured services? 

Thanks,  Terry 

     public void Identify(MapPoint ptMapPoint)
        {
            //called from btnIdentify on the toolbar - runs an Identiy on all map layers
            IdentifyTask IDTask;
            IdentifyParameters idParams = new IdentifyParameters()
                {
                    Geometry = ptMapPoint,
                    MapExtent = _Map.Extent,
                    Width = (int)_Map.ActualWidth,
                    Height = (int)_Map.ActualHeight,
                    LayerOption = LayerOption.all,
                    SpatialReference = _Map.SpatialReference
                };

             for (int i = 0; i < _Map.Layers.Count; i++)
            {
                if (!(_Map.Layers is GraphicsLayer))
                {
                    IDTask = new IdentifyTask();
                    IDTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted;
                    IDTask.Failed += IdentifyTask_Failed;
                    IDTask.Url = MapUtils.GetLayerURL(_Map.Layers);
                    IDTask.ExecuteAsync(idParams, i);
                }
                
            }
            

        }

        private void IdentifyTask_ExecuteCompleted(Object sender, IdentifyEventArgs args)
        {
            //simplified for debugging...
            if ((args.IdentifyResults != null) && (args.IdentifyResults.Count > 0))
            {
                MessageBox.Show((sender as IdentifyTask).Url + " num results= " + args.IdentifyResults.Count);
            }
            else
            {
                MessageBox.Show((sender as IdentifyTask).Url + " has no ID results");
            }
         }
        private void IdentifyTask_Failed(Object sender, TaskFailedEventArgs e)
        {
            MessageBox.Show("Identify failed. Error: " + e.Error.Message);
        }


0 Kudos
11 Replies
TerryGiles
Frequent Contributor
Hi Percy,

On that server, when I upgraded from ArcGIS Server 9.3.1 to 10.0, the issue described above stopped happening.  Never did find the real reason for the behavior though, sorry.
0 Kudos
CiprianLazar
Deactivated User
I'm still stuck on this. Below is the response that I see in Fiddler, but yet args.IdentifyResults are still null in the IdentifyTask_ExecuteCompleted routine.  


{"results":[{"layerId":1,"layerName":"Section Center","value":"W25N4934","displayFieldName":"TRS","attributes":{"OBJECTID":"31","Shape":"Point","TDIR":"W","TWNSHP":"25","RDIR":"N","RNG":"49","SECTION_":"34","TR":"W2549","TRS":"W25N4934"}},{"layerId":2,"layerName":"Section","value":"W25N4934","displayFieldName":"TRS","attributes":{  ""Object ID"":"31","Shape":"Polygon","TDIR":"W","TWNSHP":"25","RDIR":"N","RNG":"49","SECTION_":"34","TR":"W2549","TRS":"W25N4934"}}]} 


Thanks again, Terry


I was having the exact same problem and migrating from 9.3.1 to 10 did not help me. I found out the the problem was the alias of the OBJECTID field. The alias was <Object ID> (with a space) and as you can see in the quote above (the red highlight) this generated a double set of quotes resulting in a invalid JSON. So I deleted this alias from all the layers in my mxd, restarted the service and the problem was solved.
Hope this helps someone and saves a lot of time.
0 Kudos