Answered by:
Web API GET/POST end points not found

Question
-
User1584574419 posted
hi,
I have an existing VS2017 web app ( asp.net in VB). I have added in a very simple web api controller to my existing web app.
I have used Postman to generate a GET call to collect a simple string value.
I keep getting 404 errors. I have no App-_Start folder in my existing VS2017 project. Do I need to put in some kind of routing to my end points ie GET/POST etc?
I am using GET from Postman to /API/Value (my controller is called Value). Also I am using an https connection. Do I need to set up something inside my web.config
or VS2017 project? Or should I deploy a new web app on the server just to handle the web api calls?
Any thoughts greatly appreciated.
Thanks.
Tuesday, September 24, 2019 12:42 PM
Answers
-
User61956409 posted
Hi ubique,
You can try to create a new Web API project, then check if it can work as expected. And you can compare the Web API project with that existing project.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 26, 2019 1:45 AM
All replies
-
User61956409 posted
Hi ubique,
I have an existing VS2017 web app ( asp.net in VB). I have added in a very simple web api controller to my existing web app.To add and configure Web API with your existing VB application, please refer to the following steps, sample and project folder structure:
In Global.asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started GlobalConfiguration.Configure(AddressOf WebApiConfig.Register) End Sub
In WebApiConfig.vb
Public Module WebApiConfig Public Sub Register(ByVal config As HttpConfiguration) ' Web API configuration and services ' Web API routes config.MapHttpAttributeRoutes() config.Routes.MapHttpRoute( name:="DefaultApi", routeTemplate:="api/{controller}/{id}", defaults:=New With {.id = RouteParameter.Optional} ) End Sub End Module
In ValuesController
' GET api/<controller> Public Function GetValues() As IEnumerable(Of String) Return New String() {"value1", "value2"} End Function
Project folder structure
Test Result
With Regards,
Fei Han
Wednesday, September 25, 2019 2:45 AM -
User1584574419 posted
Hi Fei,
much thanks for your help. I have added in the code exactly as you describe below. I did not have a globals.asax or App_Start folder so I created them
and placed the code in as below. I did not have a Controllers folder so I added one in at project root level and created the basic Values controller class.
I am still getting error 404s - when I run under debug I can see the code being executed and the Register Sub being called. Under Postman it seems to be
saying that it cannot find the absolute path /api/Values. Does this mean my Controller was not registered correctly? I am using VS2017. Do I need to do anything
in IIS manager settings?
I also notice that when I publish to my wwwroot folder , I am missing the controller.vb file plus the App_Start folder/files. I do have the globals.asax present.
I am using VS 2017, target is .Net 4.6.1, aspnet.webapi 5.2.3 package installed.
Kind regards and thanks so much.
Chas.
Wednesday, September 25, 2019 4:12 PM -
User61956409 posted
Hi ubique,
You can try to create a new Web API project, then check if it can work as expected. And you can compare the Web API project with that existing project.
With Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 26, 2019 1:45 AM -
User1584574419 posted
Hi Fei,
I just tried exactly what you suggested and it worked first time ( tested it with Postman etc). The code looks exactly the same.
I can only think that something was wrong in my Project files with he way I added the extra folders & files.
Anyway I am up and running now. Thanks so much for all your help. I really appreciate this website and the people who share
their knowledge from all round the World. I am going to try and run something on my live server later. The server website is https but I
guess that won't affect the way the API calls work etc. Anyway I can try it and the rest is up to me to get on with.
Many thanks again for all your help and guidance. You have helped get over a real stumbling block.
All the best.
Chas.
Thursday, September 26, 2019 10:15 AM