1

I am using dotnet 7 isolated functions
I installed package Microsoft.Azure.Functions.Worker.Extensions.SignalRService
While developing locally, the negiotate function seems to be called. However, I can not get my web client (angular) to invoke any serverside (SignalRTrigger attributed) functions.

    public HostApi(SignalRService signalRService)
    {
        _signalRService = signalRService;
    } 
    
    
    [Function("Negotiate")]
    public SignalRConnectionInfo Negotiate([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequestData req,
        [SignalRConnectionInfoInput(HubName = "Hub", UserId = "{query.userid}")] SignalRConnectionInfo signalRConnectionInfo)
    {
        _logger.LogInformation("Executing negotiation.");
        return signalRConnectionInfo;
    }

    [Function("OnConnected")]
    [SignalROutput(HubName = "Hub")]
    public SignalRMessageAction OnConnected([SignalRTrigger("Hub", "connections", "connected")] SignalRInvocationContext invocationContext)
    {
        invocationContext.Headers.TryGetValue("Authorization", out var auth);
        _logger.LogInformation($"{invocationContext.ConnectionId} has connected");
        return new SignalRMessageAction("newConnection")
        {
            Arguments = new object[] { new NewConnection(invocationContext.ConnectionId, auth) },

        };
    }


    
 }  

Any ideas on how to solve this?

PhobosFerro
  • 737
  • 6
  • 18
hannes neukermans
  • 12,017
  • 7
  • 37
  • 56

1 Answers1

1

Found the solution !! You need to use the signalr emulator !!

excute commands:

 dotnet tool install  -g Microsoft.Azure.SignalR.Emulator --version 1.1.0
 asrs-emulator upstream init
 asrs-emulator start

Running these command should display a connectionstring. Then you need to copy the value in your local.settings.json file. Lik this:

"AzureSignalRConnectionString": "Endpoint=http://localhost;Port=8888;AccessKey=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGH;Version=1.0;",

Also make sure that your signalr emulator has the following settings.json

{
 "UpstreamSettings": {
      "Templates": [
         {
            "UrlTemplate": "http://localhost:7071/runtime/webhooks/signalr",
            "EventPattern": "*",
            "HubPattern": "*",
            "CategoryPattern": "*"
         }
       ]
    }
 }

This in case your function app is running on port 7071

hannes neukermans
  • 12,017
  • 7
  • 37
  • 56