Why is this virtualearth REST Url failing? RRS feed

  • Question

  • Based on code on p. 255 of Wrox's Pro Windows 8 Programming (, I am trying to call virtualearth's REST API like so:

    async internal static Task<CivicAddress> GetCivicAddress(Location location)
        HttpClient http = new HttpClient();
        StringBuilder sb = new StringBuilder("http://deb/");
        HttpResponseMessage resp = await http.GetAsync(sb.ToString());
        Stream strom = await resp.Content.ReadAsStreamAsync();
        XDocument xdoc = XDocument.Load(strom);
        XNamespace bmn = App.BingMapsNamespace;
        String addressLine = (from l in xdoc.Descendants(bmn + "AddressLine") select l).First().Value;
        String municipality = (from l in xdoc.Descendants(bmn + "Locality") select l).First().Value;
    	. . .

    ...which (sb.ToString()) ends up being (if the latitude is 44 and the longitude is -122):

        http://dev/,-122?o=xml&key=[my bing maps key]

    However, the code is bombing out, and never getting past the "*HttpResponseMessage resp = await http.GetAsync(sb.ToString());*" line. 

    I wondered if the URL was bogus, and checked the book's site for errate, but found nothing. I entered the URL directly into a browser. It tells me, **ERR_NAME_NOT_RESOLVED**

    I added a catch block to the code:

        catch (HttpRequestException hre)
            Debug.WriteLine("Exception in GetCivicAddress(): {0} Inner Ex = {1}, Stack Trace = {2}", 
                hre.Message, hre.InnerException.ToString(), hre.StackTrace); 

    ...and get, "

        Exception in GetCivicAddress(): An error occurred while sending the request. 
        Inner Ex = System.Net.WebException: The remote name could not be resolved: 'dev'
           at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
           at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar), 
        Stack Trace =    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
           at Photrax.PhotraxUtils.<GetCivicAddress>d__f.MoveNext()
        A first chance exception of type 'System.NullReferenceException' occurred in Photrax.exe

    Has virtualearth been hit by a mass injection of Corona, or what is going on here?

    B. Clay Shannon

    Saturday, October 25, 2014 4:28 AM


  • You have a mistake in the URL. It should be and not dev/

    Sunday, October 26, 2014 10:46 AM