1,105,585 Community Members

google API request and response for windows phone with C#

Member Avatar
SpyrosMet
Junior Poster in Training
54 posts since Feb 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello everyone. I have a problem trying to develop a windows phone app as a university project. Part of it is to use google APIs. So I'm trying to make a test web request.My code is as follows:

 string api_request = "https://maps.googleapis.com/maps/api/place/textsearch/xml?query=restaurants+in+Sydney&sensor=true&key=AIzaSyDpXZSLtOeGLJcYwKKJs2yAAEdfLST0ZXs";
 HttpWebRequest google_request = (HttpWebRequest)WebRequest.Create(api_request);

 HttpWebResponse google_response_file = (HttpWebResponse)google_response.GetResponse();

 StreamReader google_response_datastream = new StreamReader(google_response.GetResponseStream());

As you can see I'm creating an HttpWebRequest object and I initialize it. However, when I try to get a response I create an HttpWebResponse object but the initializer method is not accessible. After some googling I find out that insted of the HttpWebResponse initializer I have to use GetResponse() instead. Everywhere I look I find this but the C# compiler keeps considering the GetResponse method non-existent (and it is). The MSDN Documentation is completely useless and not updated whatsoever concerning the WebResponse class and its child-classes. Please help me with an up-to-date method or example :-) thank you.

Member Avatar
Momerath
Senior Poster
3,831 posts since Aug 2010
Reputation Points: 1,327 [?]
Q&As Helped to Solve: 664 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

Where does 'google_response' come from and why aren't you calling GetResponse() on the 'google_request' object, just like documentation at MSDN says?

Member Avatar
SpyrosMet
Junior Poster in Training
54 posts since Feb 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Sorry, I forgot to copy it here correctly. the line is:

HttpWebResponse google_response_file = (HttpWebResponse)google_response_file.GetResponse();
Member Avatar
Momerath
Senior Poster
3,831 posts since Aug 2010
Reputation Points: 1,327 [?]
Q&As Helped to Solve: 664 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

You have to call GetResponse() on the 'google_request' object. That will return a WebResponse which can be cast into a HttpWebResponse.

Member Avatar
SpyrosMet
Junior Poster in Training
54 posts since Feb 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I tried what you suggested but the GetResponse() method doesn't seem to exist in the class definition. Is there an alternative way to make the request and receive the data from google? (I expect an XML file to be returned)

Member Avatar
Momerath
Senior Poster
3,831 posts since Aug 2010
Reputation Points: 1,327 [?]
Q&As Helped to Solve: 664 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

http://msdn.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx

It's there. If it isn't there for you then you are missing a using or DLL reference.

Member Avatar
SpyrosMet
Junior Poster in Training
54 posts since Feb 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I included the namespace System.Net.WebResponse but still it's not recognized. does this have to do with me using visual studio 2010 express instead of 2012?

Member Avatar
Momerath
Senior Poster
3,831 posts since Aug 2010
Reputation Points: 1,327 [?]
Q&As Helped to Solve: 664 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

just System.Net, no need for the WebResponse. And no, it's existed in .NET since 1.1 at least.

Member Avatar
SpyrosMet
Junior Poster in Training
54 posts since Feb 2010
Reputation Points: -3 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I have already included the System.Net namespace but still nothing. I'm trying a different approach now. I'm requesting the data as an xml document so I am trying the following:

XmlDocument doc = new XmlDocument();
            doc.Load("https://maps.googleapis.com/maps/api/place/textsearch/xml?query=restaurants+in+Sydney&sensor=true&key=AIzaSyDpXZSLtOeGLJcYwKKJs2yAAEdfLST0ZXs");

The problem is with the XmlDocument class. I have included the System.Xml namespace but the class name and constructor are not recognized. I'm getting really upset with visual studio. There is no explanation so far as to what is wrong with the recognition of the classes and their methods. Do I need to install an extra package of namespaces or something? (I just installed Windows 8 with visual studio 2012 express for windows 8. Is there something more I need to install?)

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: