Select to view content in your preferred language

Loading legend is difficult when using authentication

2575
6
07-26-2011 06:44 AM
ReneNijkamp
Emerging Contributor
Hi,

We were using the legend example from the website (http://www.arcgis.com/home/item.html?id=901ca5cbcc6e4fe9bee960136c5971ba)
This worked like a charm, but when we enabled the authentication on the mapserver (HTTP authentication), it stopped working.

Why? In the statement
AGSMapServiceInfo* msi = ((AGSDynamicMapServiceLayer*)layer).mapServiceInfo;
is the MapServiceInfo allocated, but there are no credentials available! These are not copied from the layer itself, nor is done when the DynamicMapServiceLayer from the mapview is used to retrieve the MapServiceInfo.

Is this wanted? Because it is NOT possible to set the credentials, without recreating the whole object...

The quick and dirty fix i've used now is:
AGSMapServiceInfo* msi = [[AGSMapServiceInfo alloc] initWithURL:self.mapView.dynamicLayer.URL credential:self.mapView.dynamicLayer.credential error:&error];

This works, because there is only one dynamic layer, and only one layer (the dynamic layer) which uses the legend.

It's still work in progress, but this is the code as used:

        NSError* error = nil;
        AGSMapServiceInfo* msi;
        if (((AGSDynamicMapServiceLayer*)layer).credential.authType == AGSAuthenticationTypeNone){
            msi = ((AGSDynamicMapServiceLayer*)layer).mapServiceInfo;
        } else {
            msi = [[[AGSMapServiceInfo alloc] initWithURL:self.mapView.dynamicLayer.URL credential:self.mapView.dynamicLayer.credential error:&error] autorelease];
        }
        if (error)
            NSLog(@"Error encountered while fetching legend : %@",error);
        
        if(msi.version>=10.01){ 
   msi.delegate = self;
   [msi retrieveLegendInfo];
  }else {
   NSLog(@"Skipping layer [%@]. ArcGIS Service must be version 10 SP1 or above",msi.URL );
  }




But, it didn't work in the beginning as expected. The application gave JSON paring errors, which didn't make sense.
After a lot of research, we've found the reason: There was an "#" in the password. The legend is retrieved through http://user:password@url/MapServer/layers?f=json
Because of the # the application couldn't find the used mapserver. I guess the same is applicable for the "/" or "\", and maybe even "&"
The strange part is: With the same authentication, the mapserver itself (The map data) can be loaded...
I guess this last one is a bug... It's rather dirty anyway to put the credentials in an url..

Anyway, i really want to know if my findings are correct, and if it's a bug, or something else.

Many Thanks
0 Kudos
6 Replies
ReneNijkamp
Emerging Contributor
Changed the code a bit, this seems to work flawless:

        NSURL* layerUrl = [((AGSDynamicMapServiceLayer*)layer).URL copy];
  //Get the service info
        NSError* error = nil;
        AGSCredential* cred = [[AGSCredential alloc] initWithUser:((AGSDynamicMapServiceLayer*)layer).credential.username password:((AGSDynamicMapServiceLayer*)layer).credential.password authenticationType:[AGSCredential isServiceSecured:layerUrl]];
        msi = [[AGSMapServiceInfo alloc] initWithURL:layerUrl credential:cred error:&error];
        if (error)
            NSLog(@"Error encountered while fetching legend : %@",error);
        
        if(msi.version>=10.01){ 
   msi.delegate = self;
   [msi retrieveLegendInfo];
  }else {
   NSLog(@"Skipping layer [%@]. ArcGIS Service must be version 10 SP1 or above",msi.URL );
  }
        [layerUrl release];
        [cred release];


Note: This is only for the dynamic layer. Since we dont use feature or tiled layers, we didn't implement the legend for these types of layers.

But still, is this wanted behaviour? I would rather have that the ((AGSDynamicMapServiceLayer*)layer).mapserviceinfo (The MSI from the loaded layer) contains the credentials..

And than there is the password problem (#, /, \ in passwords result in non-loadable MapServiceInfo's)
0 Kudos
NimeshJarecha
Esri Regular Contributor
Rene,

1. Which version of the API are you using? v1.8 or v2.0?
2. Is HTTP authentication Basic or Digest?
3. Is SSL enabled on the server? 

Regards,
Nimesh
0 Kudos
ReneNijkamp
Emerging Contributor
Rene,

1. Which version of the API are you using? v1.8 or v2.0?
2. Is HTTP authentication Basic or Digest?
3. Is SSL enabled on the server? 

Regards,
Nimesh


1. v1.8, we don't want to migrate to v2.0 in this stadium (Deadline coming up)
2. I asked the dude which manages the server side: Both, including Windows Authentication
3. SSL is NOT enabled. (Internal Server)
0 Kudos
NimeshJarecha
Esri Regular Contributor
That was an issue at v1.8 but fixed in v2.0. You can test it and decide whether to upgrade or not.

IMHO, there is no risk in upgrading to v2.0. It has additional feature called popups, bug fixes and performance improvement in Graphics/Feature layer.

Regards,
Nimesh
0 Kudos
ReneNijkamp
Emerging Contributor
What do you mean by this, the authentication problem (The disappearing credentials) or the failure with the "#" in the password, or both? 😛
0 Kudos
NimeshJarecha
Esri Regular Contributor
The disappearing credential in AGSMapServiceInfo is fixed at v2.0. I don't see any problem in password having "#". I tested Tiled and Dynamic map services with password "#t/" and it works at v1.8 and v2.0.

Regards,
Nimesh
0 Kudos