In asp.net MVC web app calling an API is not working for me

Hi, I'm using VS2013, asp.net MVC and C#
I created an ASP.net MVC project (not api project).  I added entity framwork and use EF6 to create a model form an existing database.  I then added a API coontroller to the Controller folder.  I used the web API 2 with Entity framework template(creates Rest api).  Then I added the code, attached, to the Index.cshtml file to call the api using the ajax.  

I run the project and everyone shows fine in the default.cshtml page except the list of content I expect from the api call db set.  All these are done within the same project.  is that the problem?  

I'm running this from VS2013 on my dev pc.  Is there a tool or way to test if my api is working?  how can I setup the test in SOAPUI, I downloaded a copy but not sure how to test Rest that runs on my local PC and in VS2013
Thank you.
Index.html
categories.html
lapuccaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ioannis ParaskevopoulosCommented:
Hi,

Can you post your api controller?

Giannis
Craig WagnerSoftware ArchitectCommented:
Get a copy of Fiddler (http://www.telerik.com/download/fiddler) and the Chrome Postman app (https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop). Fiddler will let you see if the request you're sending is correct and Postman will let you craft the request manually and then send it to your API. If you're writing APIs these two tools are absolutely required in your toolbox.

Also, you make no mention of what the return code is from your API call. 200? 404? 401?
lapuccaAuthor Commented:
Loannis,
the attached categories file is the api controller file.
Craig,
I will installed those 2 tools, thank you.  I will update here about what I found using these tools, well, let's hope I can learned how to use them pretty quickly.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

lapuccaAuthor Commented:
What should I enter for url when testing my web services that is running on my local dev pc, inside of my VS2013?  Thank you.
Ioannis ParaskevopoulosCommented:
If you run your project, your browser will start And you will be able to see your local url. It will be something like http://localhost:12345

Just add /api/apicategories and you will get the results from your iqueryable method.
Ioannis ParaskevopoulosCommented:
You may also check the url if you see the properties of your project.
lapuccaAuthor Commented:
Fiddler and Postman looks powerful but will take some time to learn.  
I kind of know SoapUI, so I create a new REST test in there. Then, I right clicked on my project, property, click Web on the left and it shows the project url to be http://localhost:19363/
So, do I put "http://localhost:19363/api/ApiCategories " as the endpoint(correct term?) when asked to enter the URI in Soap, is this correct for URI?

i run the Get in SOAPUI and got the attached error.  i also included the screen shot of the SOAPUI.  Would appreciate it if you can have a look at my categories file and see if I'm doing anything wrong or if I'm entering the wrong URI.
soapui-error.html
soapui-screen.jpg
lapuccaAuthor Commented:
Also, in the project=>property=>Application, the target .net Framework is 4.5.  But in my VS2013,
About visual studio, it shows .net 4.6.  Does that cause a problem?
Thank you.
VS2013.txt
Ioannis ParaskevopoulosCommented:
First of all you do not need any tool to verify a web api get method. Just browse to that url and you will see the results.

Can you please post the contents of webapiconfig.cs in your App_start folder.
lapuccaAuthor Commented:
Loannis,
I ran the application in IE and invoked the Developer tool (F12), Network, then start Capturing.  At first it shows that it's calling my API with Home folder because I added the code in the Index.cshtml under the Home folder that calls it.  I then created a html file at the root of the project then call the api.  In IE it shows it's calling the right path now but still shows a 404 erro.  i attached both screen shots here.

1.  How do I ref api's uri when I'm calling api from a folder and not from the root?
2.  I suspect my problem is my project is not built with web API as part of the project template because under the App_Start folder there is not webapiconfig.cs file.  How to fix this?  
3.  Or should I just put my API code in a new project?   I think maybe this is better and cleaner.  I can keep my web application that I currently have and then put my web api in a separate project but both are under the same solution.

Thank you.
Ioannis ParaskevopoulosCommented:
You may install web api through nuget.

Right click on your project and select Manage NuGet Packages. Then search for webapi.

Alternatively you may start NuGet Package console and run:

Install-Package Microsoft.AspNet.WebApi

After this you should now have web api installed.

Then you will be able to use that url directly on your browser.
lapuccaAuthor Commented:
I used Nuget, added Web Api 2.2 but no webapiconfig file in the App_Start folder.  I then added a new API controller, still no config file.  I restarted VS and still nothing.  

I went ahead and run the application and in the developer tools in IE it still shows 404 error.  I'm attaching screen capture here.

Thank you.
IE-1.jpg
Ioannis ParaskevopoulosCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lapuccaAuthor Commented:
Loannis, that link was perfect.  I finally got it to hit my API code.  However, I'm getting all sorts of run time errors and http 500.  I will create a new web api project to start fresh.  Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.