I've been hanging on to the problem for over a week now and can't find a way to fix it because I'm pretty new to the .NET and angular environment. Also, I can't find a solution on the internet that fits my problem.
I have a service that sends me data every second via REST api. I would like to retrieve this data in the client without having to reload the whole page continuously. Therefore I have chosen SignalR.
So far everything works and the connection to the hub is set up. But when I try to call the method from the hub, I get an error message saying:
Invoking 'GetPerformanceSnapshotData' failed. Rejecting promise...
Promise rejected.
ErrorObservable {_isScalar: false, error: Error: An error occurred while sending the request.
at Object.error (http://localhost:4200/scrip......, scheduler: undefined}
error: Error. An error occurred while sending the request: An error occurred while sending the request. at Object.error (http://localhost:4200/...)...
This is my call method on the client:
public GetPerformanceSnapshotData() {
this.connect().then((connection) => {
this.invoke("GetPerformanceSnapshotData").then((data: string) => {
console.log(data);
}).catch(error => {
this.dialogService.showError(error);
return Observable.throw(error);
});
}).catch(error => {
this.dialogService.showError(error);
return Observable.throw(error);
});
}
}
The server side method looks like this:
namespace ...
{
using System.Threading.Tasks;
using System.Net.Http;
using Microsoft.AspNet.SignalR;
public class PerformanceSnapshotHub : Hub
{
public async Task<string> GetPerformanceSnapshotData()
{
using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }))
{
var response = await client.GetAsync("http://localhost:8080/api/PerformanceSnapshot");
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}
}
}
I don't understand what's wrong. Any ideas?