Lefteris Aslanoglou
Lefteris Aslanoglou

Reputation: 177

Invalid Credentials with Bing Maps on WP7, WPF, VS2010

I've got a key from http://www.bingmapsportal.com and I've added the following code to my project, as demonstrated all over the web.

In the .xaml file:

my:Map Height="320" HorizontalAlignment="Stretch" Name="map1" VerticalAlignment="Top" CredentialsProvider="fa0bb238-62bb-41b9-a1e6-459a5e9564a6"/>

(Key has been slightly edited to avoid abuse)

In the .xaml.cs file:

map1.CredentialsProvider = new ApplicationIdCredentialsProvider("fa0bb238-62bb-41b9-a1e6-459a5e9564a6");
GeocodeRequest gReq = new GeocodeRequest();
GeocodeServiceClient gSrvc = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");

gReq.Credentials = new Credentials();
gReq.Credentials.ApplicationId = "fa0bb238-62bb-41b9-a1e6-459a5e9564a6".ToUpper();

gReq.Query = address;

FilterBase[] filters = new FilterBase[2];
filters[0] = new ConfidenceFilter() { MinimumConfidence = Confidence.High };

GeocodeOptions gOpt = new GeocodeOptions();
gOpt.Filters = filters;
gReq.Options = gOpt;

gSrvc.GeocodeCompleted += new EventHandler<GeocodeCompletedEventArgs>(gSrvc_GeocodeCompleted);
gSrvc.GeocodeAsync(gReq);

But I can't get it to work, I'm getting an invalid credentials message on the map itself, and an Invalid Credentials exception with the server's response on the GeocodeRequest.

I've visited around 20 forum topics (including WP7 Bing Maps 'Invalid Credentials' Error) and I seem to have done everything they're talking about or have posted as a solution.

Any other ideas?

Upvotes: 0

Views: 1102

Answers (1)

Clemens
Clemens

Reputation: 128136

Here is how i initialize a GeocodeRequest in WP7:

GeocodeService.GeocodeRequest request = new GeocodeService.GeocodeRequest
{
    Culture = CultureInfo.CurrentUICulture.ToString(),
    Credentials = new GeocodeService.Credentials { ApplicationId = applicationId },
    UserProfile = new GeocodeService.UserProfile { DeviceType = GeocodeService.DeviceType.Mobile },
    Options = new GeocodeService.GeocodeOptions { Count = 1 },
    Query = address,
};

As you can see i don't do ToUpper() on the ApplicationId string, but i'm setting the UserProfile (and also the Culture) property. Perhaps the UserProfile.DeviceType = Mobile setting must correspond to the type of your Bing Map API key, which is certainly Mobile, too.

Maybe this is somehow helpful.

Upvotes: 2

Related Questions