Issue with Identify

1040
11
10-21-2010 07:06 AM
TerryGiles
Occasional Contributor III
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
JenniferNery
Esri Regular Contributor
If you are using SL, authentication is handled by your browser.  It is normal to see 401 on Fiddler, this just denotes that the service had required authentication and following this 401, must be a 200 with the results of your query, which means it passed the authentication process.

Since you are using Fiddler already, you can look at the webrequests made by your SL app. You can make the same requests outside your SL app by going directly to the browser and sending the same parameters.  You can look at this thread, post #14http://forums.arcgis.com/threads/14730-Area-And-Perimeter for reference. While testing outside SL app, notice that there is 401 on Fiddler.
0 Kudos
TerryGiles
Occasional Contributor III
Hi Jennifer,

Thanks for confirming that the 401 followed by 200 is normal & I do also see this just using a browser to run an Identify against the secured service. 

Any thoughts on why I can see the results of the Identify in  Fiddler's inspector but yet in my ExecuteCompleted function the args.IdentifyResults are Null?  I tried adding a proxy page and using it for the IdentifyTask but I get the same result.  Obviously I'm not doing something right, just not sure what or where to look.

Thanks again,  Terry
0 Kudos
TerryGiles
Occasional Contributor III
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
0 Kudos
TerryGiles
Occasional Contributor III
Anyone? Help??
0 Kudos
AliMirzabeigi
New Contributor
Terry,

Given the information in your posts and knowing that you have already set the spatial reference in your parameters I would suggest you check the following too:
- Does the service URL in your identify task require a ProxyUrl?
- When you sumbit an identify request to that URL is the browser prompting you for a username and password (just to make sure you have correct permission to the service)? How about the SL application you wrote? Does it also prompt for authentication when you clicked on the map?
0 Kudos
TerryGiles
Occasional Contributor III
Hi Ali,



Does the service URL in your identify task require a ProxyUrl?


I do not believe so as the security on that server is set using Windows authentication (as is my app and the Rest enpoint).  Last week while working on this I set up a proxy page and tried using it for this IdentifyTask but still get the same result - can see valid JSON results in Fiddler but args.IdentifyResult is empty.  I did modify the proxy page to use the current user's credentials as suggested by another forum post ( I added  webRequest_401.UseDefaultCredentials = true; in the getCredentials routine).  The only difference in using the proxy page was that Fiddler did not display the 401 result prior to 2nd response but that's what the proxy page is for right?

When you sumbit an identify request to that URL is the browser prompting you for a username and password (just to make sure you have correct permission to the service)? How about the SL application you wrote? Does it also prompt for authentication when you clicked on the map?


No password prompt when I try to run the Identify from the web browser & correct results are returned.

No password prompt when the layer is added to the map (added via code at runtime) or when I click in it.


Thank you Ali,

Terry
0 Kudos
AliMirzabeigi
New Contributor
Could you please make sure that your browser is not configured to enable anonymous Windows authentication? If you are using IE then:
1) Go to Tools menu --> Internet Options then Advanced tab --> scroll to the end in Security section and uncheck "Enable Integrated Windows Authentication".
2) Next, you need to go to the Security tab in the same window and click on "Local Intranet", click on "Custom Level..." button and at the end of the "Settings" list in "Security Settings - Local Intranet Zone" window select "Prompt for username and password" radio button.
** Make sure that you restart your browser to have the settings applied.

Now, visit the secured REST endpoint in your browser again and try to access the service. You should be prompted for a username and password.

If the above applies, then run your application and you should be prompted for authentication after you clicked on your map to perform the identify task.

Hope this helps.
0 Kudos
TerryGiles
Occasional Contributor III
Hi Ali,

I tried your suggestions but I cannot change the security settings for the local intranet - it's controlled by policy and the 'custom settings' button is greyed out.  Just unchecking the integrated windows auth on the Advanced tab made no difference.

Any other ideas?  Could it be a setting on the server?

Thanks again for the help,

Terry
0 Kudos
PercyJackson
New Contributor
Hi Terry,

Did you get the issue sorted out?

Thanx.

Kind Regards
0 Kudos