Select to view content in your preferred language

Using new bing map key vs token with flex 1.3 Sample Flex Viewer

2531
7
09-22-2011 03:51 PM
NeoGeo
by
Frequent Contributor
In an older post Dasa had helped someone out with getting the newer type Bing key to work with the Flex 1.3 API but not in the sample flex viewer.  Note this is temporary until we get all of our tools moved to the 2.x Flex Viewer. 

I created a file in my assets folder with this name and these contents exactly(changing the "your key here" part of course):
bing-app-id.txt:
{ "token": "your key here" }

My config.xml entry looks like this:
<mapservice label="Bing Streets" type="virtualearth" visible="false" style="road" alpha="1" 

icon="com/esri/solutions/flexviewer/assets/images/icons/i_globe.png">assets/bing-app-id.txt</mapservice>


That was the same syntax that was originally in my config.xml but of course the key is now coming from a static file instead of the ASP script generating a token.  I tried adding environment="production" but it did not make any difference.  It is still giving me Error 1009 Cannot access a property or method of a null object reference at com.esri.ags.virtualearth:VETiledLayer/commitProperties()
Any ideas?  Thanks!
Tags (2)
0 Kudos
7 Replies
NeoGeo
by
Frequent Contributor
Very strange.  This should work as the sample flex viewer already has code to handle it.  I looked in mapmanager.mxml to see what it is expecting and it is this:
      case "virtualearth":
      {
       var veTiledLayer:VETiledLayer =  new VETiledLayer();
       veTiledLayer.id = label;
        veTiledLayer.tokenURL = url;
        veTiledLayer.environment = "production";
        veTiledLayer.visible = visible; 
        veTiledLayer.alpha = alpha;
        veTiledLayer.mapStyle = style;
        veTiledLayer.name = label;
        map.addLayer(veTiledLayer);
        break;
      }
 


After changing over to a fully qualified url like http://servername/<myVirtualEarthDirectory>/bing-app-id.txt I am no longer getting an error but the map is not coming up.  I have specified all the parameters needed for a veTiledLayer, so not sure where else to look now.
0 Kudos
NeoGeo
by
Frequent Contributor
The Bing basemaps come up fine in the debugger if I put the key file under the src folder, but if I export a release build and put it on the server, the Bing Basemaps stop working.  This suggests it might be some kind of Flex security problem.
0 Kudos
NeoGeo
by
Frequent Contributor
Just me talking to myself again.
To make sure it was not a problem with Flex disliking txt files for some reason, I rewrote the vetoken.ashx file so it returns a key like this:
<% @ webhandler language="C#" class="AverageHandler" %>

using System;
using System.Web;

public class AverageHandler : IHttpHandler
{
 public bool IsReusable
 { get { return true; } }
 public void ProcessRequest(HttpContext ctx)
 {
  ctx.Response.Write("{"token": "Ahw1due6dkmZg98wUJJYLrVmYlDik4oleCgxxxxxxxxxxxxxxxImQH1HfH-asjjH"}");
 }
}

I then set up the config.xml exactly the same as the example like this:
 
 <mapservice label="Bing Aerial" type="virtualearth" visible="true" style="aerialWithLabels" alpha="1" 

icon="com/esri/solutions/flexviewer/assets/images/icons/i_globe.png">http://gis1/vetoken.ashx</mapservice>


but it still does not work on the server, only in debug mode on my workstation.  For anyone reading, yes I have a crossdomain.xml in wwwroot and it allows *
0 Kudos
NeoGeo
by
Frequent Contributor
Ok.. finally got it.  I had tried to get it to work both using a txt file and with scripts. Fiddler told me that the txt file was not getting read because of a 405 error but the scripts were getting read.  The problem with the script was that although the browser was interpreting those html style escaped quotes in both the asp and .ashx scripts I tried, the program was reading them literally.  Changing my vetoken.ashx to use the c# style escaped quotes worked like this:

<% @ webhandler language="C#" class="AverageHandler" %>

using System;
using System.Web;

public class AverageHandler : IHttpHandler
{
 public bool IsReusable
 { get { return true; } }
 public void ProcessRequest(HttpContext ctx)
 {
  ctx.Response.Write("{\"token\": \"Ahw1due6dkmZg98wUJJYLrVmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxfH-asjjH\"}");
 }
}


So basically you can just copy this code, dump it in a file named vetoken.ashx on your server, and make sure your Web Server allows asp.net.  Don't forget to edit the key to put in yours and make sure not to remove the escaped quotations.  Then you can use the example code in the config.xml file and all you have to change is the [machinename] and maybe add a folder to the path if you don't put it in the root folder (I did not put it in the root).  Note that the sample flex viewer sets the environment to "production", so if for some reason you wanted to use the test environment, you will need to modify your mapmanager.mxml and rebuild the app.
0 Kudos
NeoGeo
by
Frequent Contributor
Update... After working fine for a couple days it has stopped working for no particular reason that I can tell. Since it no longer even works in the debugger using the txt file and it doesn't work outside the sample flex viewer where it always worked before so I can only guess the key was locked out for some reason.  I will have to research that to see what the deal is.
0 Kudos
BjornSvensson
Esri Regular Contributor
It's possible that the key is no longer valid.  If you use httpfox or something similar, you should be able to see a more detailed error, for example:
"authenticationResultCode":"NotAuthorized",
"brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png",
"copyright":"Copyright © 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"errorDetails":["Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation."],
"resourceSets":[],
"statusCode":401,
"statusDescription":"Unauthorized",
...

Make sure that you use your own Bing key and not one of the Esri keys that you might have found in a sample.
0 Kudos
NeoGeo
by
Frequent Contributor
Thanks for the response.  I was not using a key from a sample.  It was our key.  I was using Fiddler since Firefox has problems on this computer (I prefer Firebug), but never got any info back like what you posted.  I will keep looking into it.  Thanks
0 Kudos