none
Getting Positions Of Interest RRS feed

  • Question

  • Hii All,

    I'm Following the Tutorial at http://msdn.microsoft.com/en-us/library/hh757509.aspx. When I try to run the example code given it gives a WebExeption.

     public XmlDocument Geocode(string addressQuery)
            {
                //Create REST Services geocode request using Locations API
                string geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations/" + addressQuery + "?o=xml&key=" + "BING_MAPS_KEY";

                //Make the request and get the response
                XmlDocument geocodeResponse = GetXmlResponse(geocodeRequest);
                //geocodeResponse.Save(Console.Out);
                //string line = Console.ReadLine();
                return (geocodeResponse);
            }


            // Submit a REST Services or Spatial Data Services request and return the response
            private XmlDocument GetXmlResponse(string requestUrl)
            {
                System.Diagnostics.Trace.WriteLine("Request URL (XML): " + requestUrl);
                HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)   //**************
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                        throw new Exception(String.Format("Server error (HTTP {0}: {1}).",
                        response.StatusCode,
                        response.StatusDescription));
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(response.GetResponseStream());
                    return xmlDoc;
                }
            }

    As it says the problem is with the line I indicated with stars.

    And also it seems like program exists GetXmlResponse function eventhough this gives exception. Because when I try to print XmlDocument to Console generated here, I got something printed. But program does not execute to the end.

    Can someone tell me what is wrong here??


    • Edited by Ricky_Brundritt Thursday, February 14, 2013 12:40 PM Removing Bing Maps key
    Wednesday, February 13, 2013 6:22 PM

Answers

  • If you want to use the REST services in .NET then follow this article: http://msdn.microsoft.com/en-us/library/jj819168.aspx

    If you want to search for points of interests then follow that article but instead of parsing the XML response from the Bing spatial Data Services pass it into a DataSet. This will save you a lot of trouble.

    Also wrap the GetResponse methods content with a try catch block so you can see why your code is throwing an error.

    One final tip. You should wrap your address with Uri.EscapeDataString as special characters will cause your URL to become invalid.


    http://rbrundritt.wordpress.com

    Thursday, February 14, 2013 12:47 PM
  • Thank you very much, There was a 1 place I haven't replaced  Bing Map Keys. After replacing it, it works.
    Thursday, February 14, 2013 4:16 PM

All replies

  • If you want to use the REST services in .NET then follow this article: http://msdn.microsoft.com/en-us/library/jj819168.aspx

    If you want to search for points of interests then follow that article but instead of parsing the XML response from the Bing spatial Data Services pass it into a DataSet. This will save you a lot of trouble.

    Also wrap the GetResponse methods content with a try catch block so you can see why your code is throwing an error.

    One final tip. You should wrap your address with Uri.EscapeDataString as special characters will cause your URL to become invalid.


    http://rbrundritt.wordpress.com

    Thursday, February 14, 2013 12:47 PM
  • Thank you very much, There was a 1 place I haven't replaced  Bing Map Keys. After replacing it, it works.
    Thursday, February 14, 2013 4:16 PM