none
Geocode service returns credential error (BadRequest/Credentials are either invalid or unspecified) RRS feed

  • Question

  • I'm searching for hours online and can't find problem.
    Please someone help. I'm sure i'm using the right VElogin and pass.

    this is my code in my web service:

    [OperationContract]
    public string GetCred()
    {
    // Add your operation implementation here
    CommonService commonService = new CommonService();
    commonService.Url = "https://staging.common.virtualearth.net/find-30/common.asmx ";

    commonService.Credentials = new System.Net.NetworkCredential("VE_Login", "VE_Pass");

    TokenSpecification tokenSpec = new TokenSpecification();
    tokenSpec.ClientIPAddress = "81.83.192.232"; //System.Web.HttpContext.Current.Request.UserHsotAddress; //this is my ip from whatismyip. the other code gave 127.0.0.1 and didn't work either
    tokenSpec.TokenValidityDurationMinutes = 480;

    return commonService.GetClientToken(tokenSpec);
    }

    this is my code at client silverlight app copied from the interactive
    silverlight SDK demo:

    private void ReverseGeocodeAsync(Location location)
    {
    request = new PlatformServices.ReverseGeocodeRequest();
    request.Culture = MyMap.Culture;
    request.Location = new PlatformServices.Location();
    request.Location.Latitude = location.Latitude;
    request.Location.Longitude = location.Longitude;

    request.ExecutionOptions = new
    PlatformServices.ExecutionOptions();
    request.ExecutionOptions.SuppressFaults = true;

    loc = location;

    ServiceReference1.Service1Client cl = new Openingsuren.ServiceReference1.Service1Client();
    cl.GetCredCompleted += new EventHandler<Openingsuren.ServiceReference1.GetCredCompletedEventArgs>(cl_GetCredCompleted);
    cl.GetCredAsync();
    }

    void cl_GetCredCompleted(object sender, Openingsuren.ServiceReference1.GetCredCompletedEventArgs e)
    {
    request.Credentials = new
    Openingsuren.PlatformServices.Credentials();
    request.Credentials.Token = e.Result;
    geocodesInProgress++;
    // Make asynchronous call to fetch the data ... pass state object.
    GeocodeClient.ReverseGeocodeAsync(request, loc);
    }


    Then the request comes back and executes this:

    private void client_ReverseGeocodeCompleted(object sender, PlatformServices.ReverseGeocodeCompletedEventArgs e)
    {

    and in this method i have a

    Openingsuren.PlatformServices.AuthenticationResultCode.InvalidCredentials

    and a
    faultreason: "Credentials are either invalid or
    unspecified."

    Strange thin CalculateRoute service works fine
    and returns a resultcode of success.

    But ReverseGeocode service return BadRequest.

    • Moved by Ricky_Brundritt Friday, March 9, 2012 2:13 PM (From:Bing Maps: Map Control and Web services Development)
    Friday, July 17, 2009 8:47 PM

Answers

  • I had exactly the same problem, then I found this:

    private GeocodeServiceClient GeocodeClient
            {
                get
                {
                    if (null == geoCodeService)
                    {
                        //Handle http/https; OutOfBrowser is currently supported on the MapControl only for http pages
                        bool httpsUriScheme = !Application.Current.IsRunningOutOfBrowser &&
                                              HtmlPage.Document.DocumentUri.Scheme.Equals(Uri.UriSchemeHttps);
                        BasicHttpBinding binding = httpsUriScheme
                                                       ? new BasicHttpBinding(BasicHttpSecurityMode.Transport)
                                                       : new BasicHttpBinding(BasicHttpSecurityMode.None);
                        var serviceUri =
                            new UriBuilder("http://dev.virtualearth.net/webservices/v1/GeocodeService/GeocodeService.svc");
                        if (httpsUriScheme)
                        {
                            //For https, change the UriSceheme to https and change it to use the default https port.
                            serviceUri.Scheme = Uri.UriSchemeHttps;
                            serviceUri.Port = -1;
                        }

                        //Create the Service Client
                        geoCodeService = new GeoCodeService.GeocodeServiceClient(
                            binding, new EndpointAddress(serviceUri.Uri));

                        geoCodeService.GeocodeCompleted += geoCodeService_GeocodeCompleted;
                        GeocodeClient.ReverseGeocodeCompleted += geoCodeService_ReverseGeocodeCompleted;
                    }
                    return geoCodeService;
                }
            }

    req.Culture = MapInstance.Culture;  //MapInstance is a reference to the mapcontrol
                MapInstance.CredentialsProvider.GetCredentials(
                    credentials =>
                    {
                        req.Credentials = credentials;
                        GeocodeClient.GeocodeAsync(req, findAdressPoint);
                    }
                );

    This is though the Bing services. To use the old services I used the DeepEarth project for services ("DeepEarth.Client.Services.Bing") for conveniency.

    Sunday, November 29, 2009 8:56 PM

All replies

  • Is your Geocode service reference pointing to staging?

    Windows Live Developer MVP - http://rbrundritt.spaces.live.com
    Sunday, November 29, 2009 11:42 AM
  • Yes

    its pointing to http://staging.dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl
    Sunday, November 29, 2009 3:39 PM
  • I had exactly the same problem, then I found this:

    private GeocodeServiceClient GeocodeClient
            {
                get
                {
                    if (null == geoCodeService)
                    {
                        //Handle http/https; OutOfBrowser is currently supported on the MapControl only for http pages
                        bool httpsUriScheme = !Application.Current.IsRunningOutOfBrowser &&
                                              HtmlPage.Document.DocumentUri.Scheme.Equals(Uri.UriSchemeHttps);
                        BasicHttpBinding binding = httpsUriScheme
                                                       ? new BasicHttpBinding(BasicHttpSecurityMode.Transport)
                                                       : new BasicHttpBinding(BasicHttpSecurityMode.None);
                        var serviceUri =
                            new UriBuilder("http://dev.virtualearth.net/webservices/v1/GeocodeService/GeocodeService.svc");
                        if (httpsUriScheme)
                        {
                            //For https, change the UriSceheme to https and change it to use the default https port.
                            serviceUri.Scheme = Uri.UriSchemeHttps;
                            serviceUri.Port = -1;
                        }

                        //Create the Service Client
                        geoCodeService = new GeoCodeService.GeocodeServiceClient(
                            binding, new EndpointAddress(serviceUri.Uri));

                        geoCodeService.GeocodeCompleted += geoCodeService_GeocodeCompleted;
                        GeocodeClient.ReverseGeocodeCompleted += geoCodeService_ReverseGeocodeCompleted;
                    }
                    return geoCodeService;
                }
            }

    req.Culture = MapInstance.Culture;  //MapInstance is a reference to the mapcontrol
                MapInstance.CredentialsProvider.GetCredentials(
                    credentials =>
                    {
                        req.Credentials = credentials;
                        GeocodeClient.GeocodeAsync(req, findAdressPoint);
                    }
                );

    This is though the Bing services. To use the old services I used the DeepEarth project for services ("DeepEarth.Client.Services.Bing") for conveniency.

    Sunday, November 29, 2009 8:56 PM
  • Can you tell me where to use this code in the project ? Thank you !


    Innovate Illuminate
    Friday, January 28, 2011 4:05 PM