Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use HttpWebRequest to call the web service API, XML library to convert the response string to .net Objects. Here is a simple example (it gets an error message "Invalid API access key supplied" as I don't have a valid key):</p> <pre><code> static void Main(string[] args) { HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create( @"http://www.ctabustracker.com/bustime/api/v1/gettime?key=89dj2he89d8j3j3ksjhdue93j" ); using (WebResponse resp = req.GetResponse()) { using (Stream respStream = resp.GetResponseStream()) { using(StreamReader reader = new StreamReader(respStream)) { String respString = reader.ReadToEnd(); Debug.WriteLine(respString); TestBusTimeResponse response = XmlUtil.DeserializeString&lt;TestBusTimeResponse&gt;(respString); Debug.WriteLine(response.Error.Message); } } } Console.ReadLine(); } </code></pre> <p>where XmlUtil.DeserializeString is defined as:</p> <pre><code> public static T DeserializeString&lt;T&gt;(String content) { using (TextReader reader = new StringReader(content)) { XmlSerializer s = new XmlSerializer(typeof(T)); return (T)s.Deserialize(reader); } } </code></pre> <p>and TestBusTimeResponse is defined as (You can actually generate this Business Object class with the XML schema, specified in the API document, using the <a href="http://msdn.microsoft.com/en-us/library/x6c1kb0s%28v=vs.90%29.aspx" rel="nofollow">xsd</a> utility shipped with VS):</p> <pre><code>[XmlRoot("error")] public class TestBusTimeResponseError { [XmlElement("msg")] public String Message { get; set; } } // Response in the following format: // &lt;?xml version="1.0"?&gt; // &lt;bustime-response&gt;&lt;error&gt;&lt;msg&gt;Invalid API access key supplied&lt;/msg&gt;&lt;/error&gt;&lt;/bustime-response&gt; [XmlRoot("bustime-response")] public class TestBusTimeResponse { [XmlElement("error")] public TestBusTimeResponseError Error { get; set; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload