CodexBloom - Programming Q&A Platform

Azure Functions - Persistent Connection implementing SignalR Service in .NET Core

👀 Views: 317 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-16
azure azure-functions signalr .net-core C#

I'm working on a personal project and I'm having trouble with I'm experiencing persistent connection issues when trying to integrate Azure SignalR Service with my Azure Functions application... I'm using .NET Core 3.1 and have set up an HTTP-triggered Azure Function that is supposed to send messages to connected clients. However, I keep getting `"Unable to connect to the SignalR service."` errors in my logs. I have followed the official documentation to set up both the Azure SignalR Service and the Azure Functions. This is my function code: ```csharp using Microsoft.AspNetCore.SignalR; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using System.Threading.Tasks; public class SignalRFunction { private readonly IHubContext<MyHub> _hubContext; public SignalRFunction(IHubContext<MyHub> hubContext) { _hubContext = hubContext; } [FunctionName("SendMessage")] public async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { string message = await new StreamReader(req.Body).ReadToEndAsync(); await _hubContext.Clients.All.SendAsync("ReceiveMessage", message); return new OkObjectResult("Message sent"); } } ``` I also have the following in my `local.settings.json`: ```json { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "AzureSignalRConnectionString": "Endpoint=https://<your-signalr-instance>.service.signalr.net;AccessKey=<your-access-key>;Version=1.0;" } } ``` I've made sure to install the necessary NuGet packages, including `Microsoft.Azure.WebJobs.Extensions.SignalRService`. Also, I confirmed that the SignalR resource is correctly configured and accessible from my Azure Functions. Despite verifying all configurations, I'm still unable to establish a connection to the SignalR service. I tried using the SignalR client directly in a console application, and it worked fine, which suggests the scenario is isolated to the Azure Function. I'm also testing this locally using the Azure Functions Core Tools version 3.0.0. What could be causing this connection scenario, and are there any recommended troubleshooting steps or configurations that I might have overlooked? I'm working in a Debian environment. I'd be grateful for any help. I'm using C# 3.9 in this project.