0
votes

i have a xamarin app that is trying to talk to use SignalR in Azure functions.

i have 2 azure functions as per the documentation.

public static class NegotiateFunction
{
    [FunctionName("negotiate")]
    public static SignalRConnectionInfo GetSignalRInfo(
         [HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
         [SignalRConnectionInfo(HubName = "chat")] SignalRConnectionInfo connectionInfo)
    //, UserId = "{headers.x-ms-client-principal-id}"
    {
        return connectionInfo;
    }
}

and

  public static class SendMessageFunction
{
    [FunctionName("Send")]
    public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message,
[SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
    {
       // var chatObj = (ChatObject)(message);

        return signalRMessages.AddAsync(
        new SignalRMessage
        {
                // the message will only be sent to this user ID
             //   UserId = chatObj.ReciversId,
            Target = "Send",
            Arguments = new[] { message }
        });
    }
}

in my xamarin client i am connecting like this.

 try
            {
                _connection = new HubConnectionBuilder()
                   .WithUrl("http://192.168.1.66:7071/api")
                    .Build();

                _connection.On<string>("Send", (message) =>
                {
                    AppendMessage(message);
                });

                await _connection.StartAsync();
            }

I send message using this code in one of the pages of Xamarin app page.

 try
        {
            await _connection.SendAsync("Send", MessageEntry.Text);
            MessageEntry.Text = "";
        }

connection code works it hits "negotiate" function properly but when i call SendAsync it does not hit break-point in [FunctionName("Send")] and nothing happens. It doesn't give me any exception as well.

local settings are like this

enter image description here

Update

i also tried Invoke. it didnt worked.

Should i try making a POST call to [FunctionName("Send")] ?

1

1 Answers

0
votes

The way SignalR SaaS works in Functions is slightly different to using the NuGet package in a .NET Application.

You can't invoke a function using the SignalR library, as you can see on the attribute in your function, it's expecting a Http trigger so you have to do a POST to this endpoint instead of invoking it as you normally would.

[HttpTrigger(AuthorizationLevel.Anonymous, "post")]

You still want to listen to the Send target as normal.