i am trying to invoke a method on my azure function from a client with signalR serverless. I am establishing a connection that is successful, however when i try to invoke a method from the client it doesn't trigger the breakpoint on the server side. What should i do?
Serverside .NET
public class PaymentHub : ServerlessHub{
[FunctionName("negotiate")]
public SignalRConnectionInfo Negociate([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req)
{
return base.Negotiate(); //this always gets triggered
}
[FunctionName("identifyUser")]
public async Task<IActionResult> IdentifyUser(
[SignalRTrigger] InvocationContext invocationContext,
string message
)
{
var x = message; //this never gets triggered
return new OkObjectResult(x);
}
}
And on the client side i am using Angular. I have a signalRService.
in signal-r.service.ts
public startConnection(){
return new Promise((resolve, reject) => {
console.log(this.connectionString);
this.hubConnection = new signalR.HubConnectionBuilder()
.withUrl(this.connectionString).build();
this.hubConnection.start()
.then(() => {
console.log("connection established");
return resolve(true);
})
.catch((err: any) => {
console.log("error occured" + err);
reject(err);
});
});
}
public test(message:string){
if(!this.hubConnection){
console.log("hubConnection doest exist");
}
else{
console.log(this.hubConnection);
this.hubConnection.invoke('identifyUser',message).then(()=>{
console.log('worked');
}).catch((error)=>{
console.log(error);
})
}
}
and in main.component.ts
ngOnInit(): void {
this.signalRService.startConnection().then(()=>{
console.log('connected');
this.signalRService.test("my message is X");
})
}
I always receive the message that the server was connected, alongside with a connectionId, but it seems like the hub doesn't trigger the method on the server side.