Sending GET requests from a .NET client to a non-WCF, plain XML web service?

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).

Up vote 0 down vote favorite share g+ share fb share tw.

I trying to write a C# client for a web service API (documentation here, PDF warning). Each request to the API is an HTTP GET call, with parameters encoded in the URI. The response is a well-formed XML document with a Content-Type of “text/xml”.

Every request must include my API key as a parameter. I could implement a web service proxy myself, but my intuition is that there is a built in . NET library written by people who actually get paid to think about this stuff.

From all my searching and reading, I think I want to use WCF, but I can't find documentation how how to use WCF as the client, making calls to a plain old XML web service. Is there anything in . NET or Visual Studio that can help me out?

I don't use svcutil. Exe, do I? Because the web service I'm talking to doesn't have any metadata.

C# .net wcf visual-studio . Net-4.0 link|improve this question asked Mar 7 at 19:15Justin14411 71% accept rate.

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): 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(respString); Debug.

WriteLine(response.Error. Message); } } } Console.ReadLine(); } where XmlUtil. DeserializeString is defined as: public static T DeserializeString(String content) { using (TextReader reader = new StringReader(content)) { XmlSerializer s = new XmlSerializer(typeof(T)); return (T)s.

Deserialize(reader); } } and TestBusTimeResponse is defined as (You can actually generate this Business Object class with the XML schema, specified in the API document, using the xsd utility shipped with VS): XmlRoot("error") public class TestBusTimeResponseError { XmlElement("msg") public String Message { get; set; } } // Response in the following format: // // Invalid API access key supplied XmlRoot("bustime-response") public class TestBusTimeResponse { XmlElement("error") public TestBusTimeResponseError Error { get; set; } }.

Thanks! I realized this was the way I needed to go, but needed help with the deserialization classes. This is a big help – Justin Mar 8 at 19:05.

Take a look at the new HttpClient class that is part of the ASP.NET Web Api. I've used it successfully to talk to the stackexchange API and it's very easy to use.

My only issue with HttpClient is that I have to form the URI and serialize the response XML each time I make a request. I was hoping to avoid this, possibly by using a tool to define the model and generate the necessary classes. – Justin Mar 7 at 19:30 I'm sure you could write a message handler that does that for you :) – Antony Scott Mar 7 at 19:46 Thanks Antony, I probably will.

I wanted to see if there was one built in to . NET, because anything that comes with the framework is probably better proven and more heavily tested than what I'd end up writing. – Justin Mar 7 at 19:55 I know that too well.

I wrote a validation operation handler in the WCF Web Api days, only to have it baked in when I migrated to ASP.NET Web Api – Antony Scott Mar 7 at 20:30.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions