I'm building an Angular2 service to log certain events, stored in ILog objects, and send them to an API to be stored in a database.
My log service is pretty straightforward:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { EnvironmentModule } from "../environment";
import { ILog } from "./log";
@Injectable()
export class LogService {
constructor(private _http: Http, private environment: EnvironmentModule) { }
postLog(log: ILog): void {
this.json = this.convertToJSON(log);
this._http.post(this.environment.getWebApiUri() + 'api/Log/PostLog/', log, {})
.subscribe(
() => console.log('Success')
); //goes to localhost:3304/WebAPI/Log/PostLog/, returns 404 not found
}
}
And it calls a WebAPI Controller that passes the data off to a service to be processed:
[RoutePrefix("api/Log")]
public class LogController : ApiController
{
private ILogService _LogService;
public LogController() : this(new LogService())
{
} //constructor
public LogController(ILogService LogService)
{
_LogService = LogService;
} //constructor
[HttpPost()]
[Route("PostLog")]
public void PostLog(Log log)
{
_LogService.PostLog(log);
} //PostLog
} //class
Yet, when my service calls the API it throws a 404 Not Found
Error.
Navigating to the path in the browser I see this:
<Error>
<Message>
No HTTP resource was found that matches the request URI
'http://localhost:3304/WebAPI/api/Log/PostLog/'.
</Message>
<MessageDetail>
No action was found on the controller 'Log' that matches the request.
</MessageDetail>
</Error>
Can anyone help me with this? I don't understand why it's behaving this way.