Hi All,
I want to call a Rest service url through MVC can any one guide me how to call.
Thnaks in advance
Srujana
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Sep 4, 2014, 11:51 PM
Hi,
there are many way to consume REST services in MVC application like you can consume by Jquery, by server side code....
Please refer
http://www.codeproject.com/Articles/233572/Build-truly-RESTful-API-and-website-using-same-ASP
http://api.jquery.com/jquery.getjson/
http://www.codeproject.com/Articles/664157/Consume-RESTful-Service-using-jQuery-in-Simple-S
hope this will help you.
Ramesh MaruthiPosted Sep 4, 2014, 10:29 AM
http://codebetter.com/johnvpetersen/2012/03/22/accessing-a-asp-net-webapi-rest-service-from-asp-net-mvc/
http://blackriver.to/2011/09/rest-service-with-asp-net-mvc-part-1/
Sample code :
class Program
{
static void Main()
{
RunAsync().Wait();
}
static async Task RunAsync()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:9000/"); // here mention ur Url as http://localhost:7083/esbGlobalServices/cacheRefresh
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// HTTP GET
HttpResponseMessage response = await client.GetAsync("api/products/1");
if (response.IsSuccessStatusCode)
{
Product product = await response.Content.ReadAsAsync
Console.WriteLine("{0}\t${1}\t{2}", product.Name, product.Price, product.Category);
}
}
}
}
}
srujana thallamPosted Sep 4, 2014, 7:32 AM
I want to call this url::http://localhost:7083/esbGlobalServices/cacheRefresh
Ho w i write code to call this.please tell me
Guest UserPosted Sep 4, 2014, 7:23 AM