What is the best way to use REST web services?

What is the best way to use REST web services from .NET?

+47
rest web-services
Nov 30 '08 at 20:02
source share
7 answers

A direct and easy approach would be to use the WebClient, which is located in the System.Net namespace.

Quite a lot of what you need to do is pass in Uri the necessary parameters needed in the form of a query string, and you should return the answer as a string, whether it be 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, you can use XmlDocument or JavaScriptSerializer to manipulate the results as needed. In any case, I suggest checking the documentation on it to see if it fits your needs. http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx

+35
Dec 01 '08 at 2:43
source share
— -

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

+9
Jul 28 '09 at 20:40
source share

There is also RestSharp , a lightweight .NET component that allows you to easily use REST web services.

+3
Aug 05 '13 at 9:57
source share
+2
Nov 30 '08 at 20:06
source share

In my opinion, the easiest way to implement the REST API is to use the Service Stack:

http://www.servicestack.net/

In my last Windows project, I made a proof of concept in WCF and ServiceStack, and the Service Stack application was faster (you can search for measurements on the Service Stack website) and easier to maintain (less code, less magical implementation). And most importantly, it helps you focus on simplicity.

+2
Jul 08 '13 at 14:49
source share

You want to consume or publish. If you want to consume, for example, make requests, the best way to interact with it is to find out what type it will use, as usual, JSON or XML. Once you have your type, you can use XmlDocument or JavaScriptSerializer to drop information and use it.

If you want to create a REST interface, you probably want to use MVC as a REST View or WCF, as @Brian said.

+1
Nov 30 '08 at 20:33
source share

If the REST services were created using the ASP.NET web API, I would use the Microsoft Http client libraries. (nuget package available). Notabene This seems to have replaced the web api client libraries that are listed in the nuget screenshot at the link below.

This will work with .NET 4, Windows Store Apps, Windows Phone 7.5 / 8, Silverlight 4 and 5.

In theory, you can use it to call any REST service created using other frameworks.

Here's a link with some examples on using the HttpClient class to call REST services: Calling a web api from a .net client

+1
Sep 23 '13 at 14:44
source share



All Articles