.net-8.0azure-signalrdotnet-isolated

SignalR client is not able to get Negotiate API response in "isolated worker model"


I have created a project where I implemented the "Negotiate" API to create the SignalR connection.

My client is in JavaScript having reference of "@microsoft/signalr@6.0.6".

On the Server side, I have implemented the "Negotiate" API as below.

I am using the following versions of the references:

Microsoft.AspNetCore.Http -> v 8.0 Microsoft.Azure.Functions.Worker -> v 1.21.0 Microsoft.Azure.Functions.Worker.Extensions.SignalRService -> v 1.13.0 Microsoft.Azure.Functions.Worker.Sdk -> v 1.17.0

using Microsoft.AspNetCore.Http;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace TestSignalRProj
{
    public class SignalRNegotiate
    {
        private readonly ILogger<SignalRNegotiate> _logger;

        public SignalRNegotiate(ILogger<SignalRNegotiate> logger)
        {
            _logger = logger;
        }

        [Function(nameof(Negotiate))]
        public static string Negotiate(
          [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
          [SignalRConnectionInfoInput(HubName = "submission")] string connectionInfo)
        {
            return connectionInfo;
        }
    }
}

When I tried to get a response from Postman, it did not return any value.

Kestral Logs

Postman Response

Reference URL I used to implement : Azure Functions SignalR Service input binding


Solution

  • I have addressed this matter by changing the return type from string to HttpResponseData class within the Microsoft.Azure.Functions.Worker.Http namespace. Additionally, I have updated the request object from HttpRequest to HttpRequestData, resulting in the following code structure. Reference : Azure SignalR Service

    [Function(nameof(Negotiate))]
    public static HttpResponseData Negotiate([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req, [SignalRConnectionInfoInput(HubName = "serverless")] string connectionInfo)
    {
          var response = req.CreateResponse(HttpStatusCode.OK);
          response.Headers.Add("Content-Type", "application/json");
          response.WriteStringAsync(connectionInfo);
          return response;
    }