how to make a call to Rest Web API from asp.net web application

Posted on 2016-08-06
Medium Priority
Last Modified: 2016-08-21
Hi, How to make a call from Rest Web API (created in VS 2013 using C# .NET 4.5) from Asp. Net web application(created in VS 2013 using .NET 4.5) .The client application is not MVC, just web application. Plz advise.

Question by:KavyaVS
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 332 total points
ID: 41745862
Please follow the steps in this link.
The example shows a console app but  the call code is valid for any .NET client.
LVL 12

Assisted Solution

funwithdotnet earned 332 total points
ID: 41746543
Right-click on References and add a service reference to the asp.net app.
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 332 total points
ID: 41747307

"Add Service References" only works for SOAP-based services, not RESTful services.
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

LVL 10

Accepted Solution

Prakash Samariya earned 1004 total points
ID: 41748281
To call/consume Rest Web API, there are various ways; you can use RestSharp (which is Http api client)


If you are familiar with HttpClient request, you can make HttpClient request and consume webapi.

Code Logic  like below: [Suppose you have Sample webapi is created]
public class Sample
	public int Id {get;set;}
	public string Name {get;set;}

//Create Helper to consume Rest WebApi
public class SampleRESTService {

    readonly string uri = "http://localhost:2236/api/Samples";

    public async Task<List<Sample>> GetSamplesAsync() {

        using (HttpClient httpClient = new HttpClient()) {

            return JsonConvert.DeserializeObject<List<Sample>>(
                await httpClient.GetStringAsync(uri)    

public class HomeController : Controller {

	//Create object of Helper Class to consume webapi
    private SampleRESTService service = new SampleRESTService();

    public async Task<ActionResult> Index() {

        //Consume webapi and get result
		return View("index", await service.GetSamplesAsync() );

Open in new window


Author Comment

ID: 41764721

Author Closing Comment

ID: 41764727

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question