Asp.net web api services - c#

What is the big difference between normal asp.net mvc and asp.net web api ? When i know i can use a normal action result to return a Json data and call it with javascript or an ajax onsuccess function or even with jquery GetJson() function.

Asp.Net MVC is used to create web applications that returns both views and data but Asp.Net Web API is used to create full blown HTTP services with easy and simple way that returns only data not view.
ASP.NET Web API vs. ASP.NET MVC “APIs”

Here is similar post ASP.NET WebApi vs MVC.
The answer is not accepted one, but the other one.
Or check this or this.

Related

Buliding an ASP.NET Core MVC web app for consuming a Web API

I'm going to build an ASP.NET Core MVC web app. That app will get its data from an API and show it on a Razor page.
My question is: should I create a class or record model to populate data from API, then show it? Is there a design pattern used in this type of apps?

MVC5 Frontend authentication through WebApi

I am developing a web application using MVC5 and WebApi2, but in seperate solutions. I have created a WebApi using ASP.NET Identity, JWT using BearerTokens and user login/creation etc is working beautifully through Postman.
I do have some problems connecting to the web api through MVC though.
The thought is that the Web Api will be deployed to Server A, and the MVC Frontend will be deployed to Server B.
I therefore need to know how to contact and retrieve information from a Web Api through MVC.
I am hoping some of you clever minds have some links to some resources or have a simple answer to the connection part of it all. I would very much prefer using C# and not JS to retrieve the data. (Although if JS is the only way, then i guess i'm learning JS)

Asp.net Web Api Configuration

I am new to asp.net mvc world. So I have a question
I have already developed a web app using Asp.net MVC (also deployed on production).
Currently I am working on mobile apps. For this I need web services (restful).
For Restful web services do I have to make a new project (within existing solution) or can I incorporate Restful webservices into my existing (Asp.net MVC) project ? (I prefer 2nd option if possible)
If I have to make new project for Web Api, then how will I deploy both projects on production knowing that Web Api project is dependent on Asp.net-MVC project ?
One thing you need to understand first is whether it's a web service,wcf service or a Web API the only thing you need is to get a json/xml output which you can use in your mobile app.
Let say you have and asp.net mvc application which has some action methods, but you might be returning a View or PartialView which is not you want for a mobile app to parse. So you need to create an action method which returns JsonResult.
If you want to use all the RESTFul verbs like POST,PUT,GET,DELETE you can add another controller which inherits from APIController and write methods there, but either ways output is same.
So it's up to you what to do and how to proceed, only thing is with an APIController you will have some more verbs and code ahve some special returns like "Ok" e.t.c

Getting 404 when trying to hit the WebAPI controller method

I have created a project using ASP.NET Core Web Application (.NET Framework). My project structure:
My values controller is inherited from an MVC controller. When I hit http://localhost:20798/api/values, I do get the desired response.
I added ConsumerScore controller, this time a WebAPI controller inheriting from ApiController. But now when I hit http://localhost:20798/api/consumerscore, I am getting 404 response.
My ConsumerScore controller looks like:
How to resolve this error?
The error is with the "ApiController" you should use just Controller in your implementation.
There is indeed to particular ApiController class anymore since MVC and WebAPI have been merged in ASP.NET Core. However, the Controller class of MVC brings in a bunch of features you probably won't need when developing just a Web API, such as a views and model binding.
for more see: Is ApiController deprecated in .NET CORE?
Seems like you are confusing the idea of "MVC" and "Web API".
ASP.net MVC is used for serving web pages while the Web API is supposed to be serving data in a negotiable way (json/xml/...) to http requests.
Adding an "api/*" to an MVC route and serving data from an MVC Controller is not the best idea and will not turn it into a useful web service.
From the look of your methods, I suppose what you need is an ApiController but you cannot create the http request by copying the "~/api/*" to your web browser and you need to use tools like fiddler or your browser's debugger.

How to upload text to an ASP.NET MVC 2 Action from a Windows Application

I'm new to asp.net mvc and web development in general and would like to know the best way to pass text from a windows application written in c# to a asp.net mvc website so it can be stored in a database. Is it possible to call a controller action (via a url similar to REST) from the Windows application or do I need to create a web service? If someone can point me to a verbose example that would be great.
Thanks
You can use the WebClient class. Look here for a simple sample.
Hope this helps.
Why do you want to pass it to your MVC site to store in the database? How are you interacting with your database in the MVC site?
If you have two different applications that need to access the data you should put it in a separate layer and may be create a WCF service or a Web Service.

Categories