I have the following call to a selfhosted OWIN API:
const string baseAddress = "http://localhost:9000/";
using (WebApp.Start<ApiSelfHost>(url: baseAddress))
{
var client = new HttpClient();
var response = client.GetAsync(baseAddress + "api/v1/orders/test/status").Result;
}
Which is based on (I got that working):
Use OWIN to Self-Host ASP.NET Web API
The response returns the following:
StatusCode: 404, ReasonPhrase: 'Not Found'
But if I run the actual API and go to:
http://localhost:51823/api/v1/orders/test/status
I get a valid response.
That controller action has this signature:
[HttpGet]
[Route("api/v1/orders/{orderReference}/status")]
public IHttpActionResult GetOrderStatus([FromUri]string orderReference)
I tried changing that port 9000 to 51823, just to be sure, but that doesn't matter.
I have the following OWIN packages installed:
<package id="Microsoft.Owin" version="4.0.1" targetFramework="net471" />
<package id="Microsoft.Owin.Host.HttpListener" version="4.0.1" targetFramework="net471" />
<package id="Microsoft.Owin.Hosting" version="4.0.1" targetFramework="net471" />
<package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net471" />
<package id="Microsoft.Owin.Security.Jwt" version="3.0.1" targetFramework="net471" />
<package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net471" />
<package id="Microsoft.Owin.Testing" version="4.0.1" targetFramework="net471" />
Question
Any pointers to why the url cannot be found (throws 404)?
A few hours later I got it working! As was to be expected it was something deeper:
My controller gave this error:
Despite having set up IoC type registrations:
I was however missing this line:
Full startup set up with injection:
Where
ConfigureAutofacis an extension onHttpConfiguration:And one on
ContainerBuilderas well:Startupbase class is the actual one from the API.