Last post May 10, 2015 11:55 PM by asadsiddiqi
May 07, 2015 09:26 PM|asadsiddiqi|LINK
I want to call a webapi 2 service from MVC 5 controller, can anybody please help me out and give me some easy to understand examples.
May 07, 2015 11:37 PM|santhoshje|LINK
You can call with following code
Web Api Controller
public class ValuesController : ApiController
// GET api/values/5
public string Get(int id)
Code to call Web Api from MVC
using (var client = new HttpClient())
client.BaseAddress = new Uri("http://localhost:58745");
var response = client.GetAsync("api/values/10").Result;
string responseString = response.Content.ReadAsStringAsync().Result;
May 08, 2015 01:03 AM|asadsiddiqi|LINK
Hi Santoshje, Thanks for your reply mate, i just have query regarding async and synchronous call, this is i think async call, can you please tell me if i want to do synchronous call what should it be.
May 08, 2015 07:14 PM|santhoshje|LINK
Please use following code
using(var client = new WebClient())
string response = client.DownloadString("http://localhost:58745/api/values/10");
May 10, 2015 11:55 PM|asadsiddiqi|LINK
Thanks very much Sathoshje, much appreciated.