4

I'm building my first Azure Function App with SignalR trigger binding following this guide. I already have my Function App and my SignalR Service set up in Azure.

But now I need to debug one of my SignalR triggered functions. I'm trying to do this using Visual Studio 2022 using the local functions host (func.exe), by simply pressing F5 in my Azure Functions project.

I have my ServerlessHub with a function JoinGroup that I want to invoke and debug in Visual Studio.

        namespace FunctionApp
        {
            public class SimpleChat : ServerlessHub
            {
                [FunctionName("negotiate")]
                public SignalRConnectionInfo Negotiate([HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req)
                {
                    var claims = GetClaims(req.Headers["Authorization"]);
                    return Negotiate(
                        claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value,
                        claims
                    );
                }

                [FunctionName(nameof(JoinGroup))]
                public async Task JoinGroup([SignalRTrigger]InvocationContext invocationContext, string connectionId, string groupName)
                {
                    throw new ApplicationException("CODE REACHED");
                    await Groups.AddToGroupAsync(connectionId, groupName);
                }
            }
        }

I've also written a simple client in typescript with a single method with which I want to invoke my JoinGroup function:

            testjoinGroup(){
                if (this.isConnected()) {
                    this.hubConnection.invoke<any>("joinGroup", "testGroupName")
                        .then(x => console.log("success"))
                        .catch(err => console.log(err)):
                }
            }

The connection is created successfully, the negotiate calls go through, and the above method testjoinGroup() prints "success" when I call it. However, I don't hit the breakpoint in visual studio. I'm not getting any errors either in my web app or VS. I've configured my 'local.settings.json' to connect to my SignalR instance.

Is what I'm trying to do simply not possible? Do I need to deploy my changes to Azure in order to test the new code?

  • I'm using Visual Studio 2022 with the Azure Development workload installed.
  • My version is .NET 6.
  • Using Microsoft.Azure.Webjobs.Extenions.SignalRServicce 1.8.0
lopezbertoni
  • 3,551
  • 3
  • 37
  • 53
user1531921
  • 1,372
  • 4
  • 18
  • 36
  • Have you checked out this question, it may be helpful? https://stackoverflow.com/questions/73982004/local-development-with-azure-signalr-service-and-azure-functions – Niels Filter Jan 17 '23 at 08:23
  • have you set the upstream which will point function? – Pavan Jan 17 '23 at 12:01
  • @Pavan I'm not sure I understand your question? – user1531921 Jan 17 '23 at 15:14
  • @NielsFilter Thanks, I'll take a look at it. Can't believe I didn't find it. It seems to sort of answer my question but I cannot believe the only way to do this is to use that emulator. – user1531921 Jan 17 '23 at 15:15

0 Answers0