Azure Functions SignalR setup on Azure

Bubba Jones 211 Reputation points
2023-06-13T14:11:29.4+00:00

I had the following setup;

  1. A SignalR service running locally via emulator
  2. An azure functions app running locally
  3. An AspNetCore client that invoked the above azure functions app

The azure functions app connected to my locally running SignalR emulator, and the AspNetCore client was able to get SignalR responses. In other words the entire above setup was working.

I now have the following setup:

  1. A SignalR service running on azure
  2. An azure functions app published on azure
  3. An AspNetCore client that invokes the above azure functions app

Upon invoking the azure functions negotiate function my AspNetCore client I got an exception. The server logs of my negotiate function in azure displayed the following:

2023-06-03 19:48:26.492 Executing 'Functions.Negotiate' (Reason='This function was programmatically called via the host APIs.', Id=d4e0992c-0e72-4b3a-beb6-e5e6b0c6cbf4)

Information
2023-06-03 19:48:26.572
AzureSignalRServiceTransportType not set, using default Transient instead.

Information
2023-06-03 19:48:26.682
The SignalR Service connection string or endpoints are not set.

Error
2023-06-03 19:48:26.682
Executed 'Functions.Negotiate' (Failed, Id=d4e0992c-0e72-4b3a-beb6-e5e6b0c6cbf4, Duration=113ms)

Error
2023-06-03 19:48:26.711
The SignalR Service connection string or endpoints are not set.
Error

Right now I see three possibilities:

  1. My azure functions app is not configured to point to my azure based SignalR service running on azure. When running locally my azure functions app was configured to connected to the singalR emulator via a local.settings.json. file. I understand this file is NOT deployed onto azure when publishing the functions app. Therefore the functions app running on azure has no way of knowing how to connect to the SignalR service.
  2. The signalR service is not configured correctly.
  3. Both of the above.

Something is not configured correctly and I am not sure where to start. Again my setup has worked when running locally, but it was when I published to azure that I faced problems. Any input would be highly appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,123 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
147 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sedat SALMAN 14,065 Reputation points MVP
    2023-06-13T22:24:57.5466667+00:00

    According to your logs, the problem appears to be caused by a missing SignalR Service connection string or endpoints. When running locally, you had a file called local.settings.json that contained your connection settings. However, because this file was not deployed when you moved to Azure, your Azure Function does not know how to connect to the SignalR Service.

    Here are some points that might help you to resolve the issue:

    Azure Functions and SignalR Service Setup: Your Azure Function app needs to be configured correctly to use Azure SignalR Service.

    • Azure SignalR Service needs to be configured in Serverless mode when used with Azure Functions.
    • Azure Functions should have a negotiate function that the client calls to obtain a valid SignalR Service access token and endpoint URL.
    • Your Azure Functions app should have one or more functions that handle messages sent from SignalR Service to clients. These functions use the SignalRTrigger binding to handle messages sent from the SignalR Service.
    • Use the SignalR output binding to send messages to clients connected to Azure SignalR Service.
    • SignalR has a concept of hubs, which are logical namespaces that separate connections and messages. Each client connection and each message sent from Azure Functions is scoped to a specific hub.
    • If you're using C#, you can use the class-based model, which simplifies many aspects of the setup. For instance, you don't need the SignalRConnectionInfo input binding and can add custom claims more easily.

    Ensure the correct connection settings are used for your Azure SignalR service. This seems to be the primary issue you're encountering. When you were running locally, your Azure Functions app was able to connect to your SignalR service using settings from the local.settings.json file. However, when you deploy your Azure Functions app to Azure, the local.settings.json file does not get deployed, so your app doesn't have the connection settings it needs. To resolve this, you need to set up the necessary connection settings in the Azure portal. Go to your Azure Functions app in the portal, and under the 'Settings' section, click on 'Configuration'. Here, you can add new application settings that match the ones you had in your local.settings.json file. These settings will then be available to your Azure Functions app when it's running in Azure.

    Ensure that your client application is correctly configured to connect to the Azure SignalR service. The client must make a request to the negotiate HTTP endpoint to obtain valid connection information and then connect to SignalR Service using the service endpoint URL and access token obtained from the negotiate endpoint.


  2. Bubba Jones 211 Reputation points
    2023-06-14T07:54:28.5233333+00:00

    You had a file called local.settings.json that contained your connection settings. However, because this file was not deployed when you moved to Azure, your Azure Function does not know how to connect to the SignalR Service

    This was what I suspected; in the absence of a local.settings.json file when deploying my functions app on azure. I have made changes by adding AzureSignalRConnectionString

    I will test this out and get back you. I hope I have to add it under the Application settings section and not Connection strings setting.

    Settings.png

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.