Then it should be a simple matter of taking the URL example, copying it to bowser address line, change localhost the IP of the machine hosting the service, a possible port number and the name of the controller for an action method in the controller.
try to get a response from http://localhost:8081/weatherforecast in the browser on the machine that is hosting the WebAPI, which in the test controller created by the WebAPI template for a WebAPI project by Visual Stuido.
using (var client = new HttpClient())
{
var uri = new Uri("http://localhost:8081/payroll/GetAll");
var response = client.GetAsync(uri).Result;
if (!response.IsSuccessStatusCode)
throw new Exception(response.ToString());
var responseContent = response.Content;
var responseString = responseContent.ReadAsStringAsync().Result;
dynamic payrolls = JArray.Parse(responseString) as JArray;
foreach (var obj in payrolls)
{
DtoPayroll dto = obj.ToObject<DtoPayroll>();
dtopayrolls.Add(dto);
}
}
If you find the post has answered your issue, then please mark post as 'answered'.
I configure the host file to this (127.0.0.1 internalapi ) so that if I put internalapi/[myapiname]/controller . it should work, but its not working
which machine did you do this on? if the new server, then this only works for a browser running on that server. if done on your local box, it points to your local box, not the server.
Member
4 Points
29 Posts
asp.net core web api hosting
Feb 24, 2020 08:24 AM|techasuran|LINK
Hi all,
I am very new to asp.net webapi.
developed a webapi (core 3.0), need to host it on local machine in our compnay network.
I published to local folder and copied to folder in new machined where we need to host and pointed the hysical path as "C:\SourceCode\PublishApi"
its as widnows 10 Pro and have installed the ASP.NET Core 3.0 Runtime (v3.0.3) after setting up the iis.
I configure the host file to this (127.0.0.1 internalapi ) so that if I put internalapi/[myapiname]/controller . it should work, but its not working
if try browsing the website , getting the below error in the browser.
Hmmm...can’t reach this page
Try this
Make sure you’ve got the right web
can anybody help me on this.
Contributor
4983 Points
4265 Posts
Re: asp.net core web api hosting
Feb 24, 2020 02:55 PM|DA924|LINK
You followed what is in the link, right?
https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=visual-studio
Then it should be a simple matter of taking the URL example, copying it to bowser address line, change localhost the IP of the machine hosting the service, a possible port number and the name of the controller for an action method in the controller.
try to get a response from http://localhost:8081/weatherforecast in the browser on the machine that is hosting the WebAPI, which in the test controller created by the WebAPI template for a WebAPI project by Visual Stuido.
All-Star
58484 Points
15809 Posts
Re: asp.net core web api hosting
Feb 24, 2020 03:25 PM|bruce (sqlwork.com)|LINK
which machine did you do this on? if the new server, then this only works for a browser running on that server. if done on your local box, it points to your local box, not the server.