locked
Bing geocode service always returns Credentials are either invalid or unspecified RRS feed

  • Question

  • I'm trying to use the Bing geocode web service. With an existing Application Key and even a new created Application Key at Bing Maps Account center, I always get "Credentials are either invalid or unspecified." I searched on the internet and found so many posts on this subject, but couldn't find a solution for my problem. Can somebody please point out the problem in my code?

    I followed the documentation here:

    http://msdn.microsoft.com/en-us/library/cc966738.aspx

    And the WSDL is:

    http://dev.virtualearth.net/webservices/v1/metadata/geocodeservice/geocodeservice.wsdl

    My code is here:

        public GeocodeResponse getGeoCode(String street, String city,
                String state, String zipCode)
        {
            net.virtualearth.dev.webservices.v1.common.ObjectFactory object =
                new net.virtualearth.dev.webservices.v1.common.ObjectFactory();
           
            GeocodeRequest request = new GeocodeRequest();
            request.setAddress(object.createAddress(getAddress(street,city,state,zipCode)));
            request.setCredentials(object.createCredentials(getCredentials()));
           
            GeocodeResponse response = getGeoCodeCommon(request);
            return response;
        }

        private GeocodeResponse getGeoCodeCommon(GeocodeRequest request)
        {
            GeocodeService geocodeService = new GeocodeService();
            IGeocodeService igeo = geocodeService.getBasicHttpBindingIGeocodeService();
           
            GeocodeResponse response = null;
            try {
                response = igeo.geocode(request);
            } catch (IGeocodeServiceGeocodeResponseSummaryFaultFaultMessage e) {
                logger.info(e.getMessage());
            }
           
            return response;
        }

        private Address getAddress(String street, String city, String state, String zipCode)
        {
            com.microsoft.schemas._2003._10.serialization.ObjectFactory object =
                new com.microsoft.schemas._2003._10.serialization.ObjectFactory();
           
            Address address = new Address();
            address.setAddressLine(object.createString(street));
            address.setLocality(object.createString(city));
            address.setAdminDistrict(object.createString(state));
            address.setPostalCode(object.createString(zipCode));
           
            return address;
        }

        private Credentials getCredentials()
        {
            com.microsoft.schemas._2003._10.serialization.ObjectFactory object =
                new com.microsoft.schemas._2003._10.serialization.ObjectFactory();
           
            Credentials credentials = new Credentials();
            credentials.setApplicationId(object.createString(myMapKey));
            return credentials;
        }



    • Moved by Ricky_Brundritt Saturday, March 10, 2012 12:07 PM (From:Bing Maps: Map Control and Web services Development)
    Tuesday, November 15, 2011 5:04 PM

Answers

All replies

  • One thing worth trying is to change the name of your variable to something other than object. I can see this potentially causing an issue. Also, why are you using ObjectFactory? Can you just place your key into the setApplicationId method to ensure that it is being passed? Check this documentation out and verify this method works for you: http://msdn.microsoft.com/en-us/library/cc980855.aspx
    http://rbrundritt.wordpress.com
    Wednesday, November 16, 2011 6:04 PM
  • The reason I used ObjectFactory because object fields generated from WSDL have JAXBElement types. I managed to have JAXBElement not generated by using bindings. Now the code is working.

     

    Thank you very much for the help.


     

    Wednesday, November 16, 2011 8:22 PM
  • Hmm... ok. I thought you were using .NET and not Java. Take a look at this blog post:http://ngjon.wordpress.com/2010/01/19/simple-java-starter-applications-using-bing-maps-web-services/ Personally I recommend using the REST services over the SOAP services as they are faster, have more features and are easier to use cross platforms.
    http://rbrundritt.wordpress.com
    Thursday, November 17, 2011 10:13 PM