Consume Web API2 using MVC

In this code sample I try to demostrate how to consume ASP.NET WEB API hosted on another server (as a REST services only) using ASP.NET MVC4 (as a client) with RESTSHARP.To play with the source code, one should have: Visual Studio 2013 express or later ASP.NET MVC4 or later

C# (699.6 KB)
 
 
 
 
 
5 Star
(1)
885 times
Add to favorites
10/12/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Can you please explain how to compile this solution
    7 Posts | Last post October 18, 2016
    • Hello,
      
      I would like to learn how to do what you are showing in this solution.
      
      Can you please explain how to compile it after I download the zip file and installed it in it's own folder.
      
      I have Visual Studio 2015 and ASP.NET Core, API2.  I opened the solution in VS2015, but when I build it, I get this error:
      "Error		This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.	consumewebapiusingrestsharp	C:\Users\Tony\Documents\Visual Studio 2015\Projects\TestWebAPIMVC\C#\consumewebapiusingrestsharp\consumewebapiusingrestsharp.csproj	270"
      
      Thanks for any help that you can provide to resolve this error.
      
      Tony
    • Hi Tony,
      
      Steps to build this project are very simple:
      1. Download source code
      2. Extract the folder
      3. Open Solution using preferred (check pre-requisite) Visual Studio version
      4. Now, just build (ctrl+B) the solution
      5. You may get few build errors due to missing NugetPackage
      5.1. Check output windows to know what packages are missing
      5.2 Restore missing Nuget packages or you can re-install the packages
      5.3 Rebuild solution again
      6. Now, you would be able to run the project.
      
      Feel free to contact, if you need further information.
    • Hello Gaurav.
      
      Thanks for your help.
      
      I tried your steps.  I opened the solution in Visual Studio 2013.  I did a build of the solution.  It gave 38 warnings similar to this: "Warning	31	The referenced component 'Antlr3.Runtime' could not be found. 	consumewebapiusingrestsharp"
      
      I ran the "Manage Nuget Packages".  I selected the nuget.org under Updates on the left.  I updated all packages that it showed.  I ran the rebuild again and it still gave all of the warnings.
      
      I noticed that under the References in the Solution tab all of the references had a yellow "I" on them.  If I delete one of those references and try to add it back using the Add Reference, it still appeared with the yellow "I" on the reference.  I tried that for other references and got the same results.
      
      It won't let me update the references.
      
      Any help that you can provide to resolve those warnings would be gratefully appreciated.
      
      Thanks,
      Tony
    • Hi Tony
      
      I am really sorry that you're facing few issues while compiling the project. I downloaded the zip and tried same steps after restoring packages, I am able to run the project.
      
      Alternatively, would you mind to download complete solution (of 2 projects) from  here: https://github.com/garora/somestuff
      
      Try to build and run this project and let me know if you are facing any issue, I will give you standalone project or we can also discuss via TeamViewer or over skype call.
      
      Regards,
      Gaurav Arora
    • Gaurav
      
      That worked for me.  I downloaded, rebuilt and ran without a problem.
      
      Thanks for your help.
      
      Tony
    • @Tony - Glad to hear that. You'd like to rate this sample.
    • Gaurav,
      
      I would be happy to rate this sample.  Please explain how I would do that.
      
      Also, I see in the latest solution sample that I have tested with and had success, there is a project called "MyStuff".  What is the purpose of that project as it relates to this sample project of "ConsumeWebApi"?
      
      Thanks again for your help.
      
      Tony
  • Using RestSharp
    2 Posts | Last post October 18, 2016
    • Thanks for a good example.
      I downloaded the project and able to build and run, unfortunately, I am getting issue while making POST request and drilled down and found that it is due to RestSharp, could you please provide some insight on this?
      
      
    • @Shuby - Could you please share the exact scenario and problem here? POST request is working fine for me.