Select to view content in your preferred language

Sending token(s) to Non-ArcGIS WMS services

1550
2
11-01-2012 10:08 AM
JeremyWiebe
Emerging Contributor
Hi all,

We are using the ArcGIS v3.2 Javascript API.  Most of our mapping is done by ArcGIS, but we have a swappable base layer that we allow the user to change (aerial and satellite imagery or topography).  We are doing this using an esri.layers.WMSLayer().

The service that is supplying this imagery is proxied through a mapproxy (http://mapproxy.org/) server.  Some of these proxied layers we have to pay for per-request and require a user token with each request.  

I've been looking at the IdentityManager and IdentityManagerBase classes but from what I've read they're only applicable if you are using a secured ArcGIS server. 

Does anyone have any ideas on how this might be done?   I've tried embedding the tokens in the url when creating the WMSLayer but those are stripped when the javascript API starts calling out to the service.  Well, to be clear, the token remains in the first call to our proxy page (esri.config.defaults.io.proxyUrl) but is then gone when the API makes a direct call to the mapproxy service. 

The request to the proxy page looks like this (I've removed the actual IP):

http://localhost:47689/Map/Proxy.ashx?http://1.1.1.1/mapproxy/service?token=zzzzz&SERVICE=WMS&REQUES...

Then the API goes directly to the proxied page:

http://1.1.1.1/mapproxy/service?SERVICE=WMS&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=TRUE&STYLES=...
0 Kudos
2 Replies
JeremyWiebe
Emerging Contributor
Just a follow-up to my original question.  I found an alternate way to handle this.  The ArcGIS API will always hit the Proxy.ashx handler (we're on .NET) if we set the esri.config.defaults.io.proxyUrl setting.  So in the proxy handler I watch for GetCapabilities requests and rewrite the server URL's in the XML response to be routed through the proxy handler as well.  This works out well as we then have full control in the proxy handler to do whatever we want.
0 Kudos
JonasEngedal
Deactivated User
I am having the same problem and have solved it in another way. I am not sure which one I prefer.

My approach is to subclass esri.layers.WMSLayer and override getImageUrl:

    
    getImageUrl: function (extent, width, height, callback) {
        // If applicable prefix with proxy url to let proxy handle authentication
        if (esri.config.defaults.io.proxyUrl && !this.proxyUrlPrefixed) {
            this.getMapURL = esri.config.defaults.io.proxyUrl + "?" + this.getMapURL;
            this.proxyUrlPrefixed = true;
        }

        this.inherited(arguments);
    }


The same approach can be used for WMTSLayer by overriding getTileUrl.

Does anyone know the reason why WMSLayer and WMTSLayer do not call the proxy when requesting GetMap and GetTile?
0 Kudos