What is the best way to consume REST web services? [closed]

Solution 1:

A straight forward and easy approach would be to use WebClient which is in the System.Net namespace.

Pretty much all you need to do is pass in the Uri required with any parameters needed in the form of a query string and you should get back the response in the form of a string, be it json or xml. For example.

using System.Net; 

string param = "hello";

string url = String.Format("http://somedomain.com/samplerequest?greeting={0}",param);

WebClient serviceRequest = new WebClient();
string response = serviceRequest.DownloadString(new Uri(url));

Then, like Nick mentioned, you can use XmlDocument or JavaScriptSerializer to manipulate the results as needed. Anyway I suggest checking out the documentation on it to see if it meets your needs. http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx

Solution 2:

Instead using WebClient like Kenney, you can use HttpWebRequest and HttpWebResponse and process the result with a StreamReader and XmlDocument .