using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Xml.Linq;namespace RestServiceClient{ /// /// REST Client to GET or POST the data /// public class RestClient { private string responseData = String.Empty; //private string url = String.Empty; public string Url { get; set; } public string Data { get; set; } private WebClient client; /// /// Download Data from REST Service in Synchronous way. /// /// /// Response Data from Service public String GetDataSync(string url) { using (client = new WebClient()) { responseData = GetXmlData(client.DownloadString(new Uri(url))); } return responseData; } /// /// Upload/Post Data using REST Service in Synchronous way. /// /// /// /// Response Data from Service public String PostDataSync(string url, string data) { using (client = new WebClient()) { responseData = GetXmlData(client.UploadString(new Uri(url), data)); } return responseData; } private String GetXmlData(String xml) { XElement doc = XElement.Parse(xml); return doc.ToString(); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Management.Instrumentation;using System.Management;using System.Threading;using RestServiceClient;namespace RestClientApplication{ class Program { public static void Main(string[] args) { RestClient client = new RestClient(); string url = "http://www.thomas-bayer.com/sqlrest/CUSTOMER/"; Console.WriteLine(client.GetDataSync(url)); Console.Read(); } }}