简体   繁体   中英

unable to send content from client to server using azure functions signalR

we are trying to send content from the client to server using azure functions signalR implementation. however the azure function SendToUser method is not being called.

client code:

//building connection
hubConnection = new HubConnectionBuilder().WithUrl("http://localhost:7071/api").Build();

//starting connection
await hubConnection.StartAsync();

//sending data
hubConnection.InvokeAsync("SendToUser", "message", "user");

server code:

[FunctionName("Negotiate")]
public static SignalRConnectionInfo Negotiate([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, [SignalRConnectionInfo(HubName = "ChatHub")] SignalRConnectionInfo connectionInfo, ILogger log)
{
    log.LogInformation($"connection {connectionInfo.Url} {connectionInfo.AccessToken}");
    return connectionInfo;
}

[FunctionName("SendToUser")]
public void SendToUser([HttpTrigger(AuthorizationLevel.Anonymous, "post")] obj message, HttpRequest req, [SignalR(HubName = "ChatHub")] IAsyncCollector<SignalRMessage> signalRMessage, ILogger log)
{
    log.LogInformation($"message sent by client");
}

is this the correct implementation for this?

  • To consume the messages, you will have to use the azure service trigger bindings in the function.

  • For that you will need SignalRTrigger instead of the httptrigger you have passed.

code:

[FunctionName("SendToUser")]
public void SendToUser([SignalRTrigger]InvocationContext invocationContext, string message, ILogger logger) 
{
     logger.LogInformation($"{message} "); 
}

You can refer these MSDOC on azure service trigger bindings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM