Aspnetcore.docs: Client Only Guidance

Created on 24 Mar 2020  Â·  13Comments  Â·  Source: dotnet/AspNetCore.Docs

Is there any documentation on how to connect to Azure SignalR using only the client WebAssembly (not hosted in .Net Core)? My goal is to be able to host from a static file server and connect to SignalR to receive published events in real time. If this is not possible is there another Azure solution in the free tier which has Client only support? I'd really like to avoid having to integrate the Google SDK and Firebase just for this one feature.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

SignalR Source - Docs.ms doc-idea

Most helpful comment

The 3.1.4 version of the client will have a fix for the access token, so you won't need to hack it into the url.

All 13 comments

Hello @vanderstack ... I'm only aware that you can host a Blazor Server app in the Azure SignalR service. I'm not sure about a back-end hub app with a statically-hosted Blazor WebAssembly app.

It seems like the answer should be 'yes, it can work,' but we'll need to find out from management. It might turn out to be one of those 🔧 Hack It!:tm: 🔧 scenarios that you can make work. For example, go Hosted at first, then split out the Client app and host it statically while hosting the Server app in Azure SignalR ... something like that.

There definitely isn't a doc; so if they do say that it's possible, we can also find out if they want to keep this issue to provide such a doc in the future. Alternatively if a pattern similar to what I said will work, then we can add a section to one of the reference topics in the Blazor doc set.

They usually triage these on Fridays, so sit tight for a bit. In the meantime, you can consult with devs on the usual support channels and check the blog-o-sphere ...

After discussing further in the Gitter channel I felt it would be helpful to provide more details.

Use Case: I have an IoT sensor which publishes data to SignalR using the rest API on an unpredictable timeline. The payload sent by the IoT sensor is signed similar to a JWT so that consumers can verify the author is trusted. No other data is intentionally published and no other sources except this sensor are trusted authors. This data only provides value while a client is connected to consume it. An arbitrary number of browser clients should be able to consume the Azure SignalR service, verifying the author and otherwise ignoring the data.

The documentation here contains the following diagram:
contains the following diagram
My goal is to avoid using an Azure Function, and instead have the negotiate and broadcast functions handled by an arbitrary instance of the web assembly app running on an arbitrary client, which means as long as someone is using the WebAssembly App the SignalR service will be available to all users.

@bradygaster should this just work? Is there anything that would prevent using Azure SignalR service from a Blazor WASM client?

I have a Blazor WebAssembly app running as an Azure App Service and after following the Azure SignalR Service tutorial I get the following error on the client:
dotnet.3.2.0-preview3.20168.1.js:1 WebSocket connection to 'wss://covid-19.service.signalr.net/client/?hub=statemapupdatehub&asrs.op=%2FStateMapUpdateHub&negotiateVersion=1&asrs_request_id=fJkA5BVMAQA%3D&id=BwIiQfqiV7g2EQWJTTAqwA4ae08df31' failed: HTTP Authentication failed; no valid credentials available
My application does not use authentication, it is just a dashboard that I wish to update. Is there a reason for this error?

Ping @bradygaster

@BrunoBlanes: you must include access_token in the url and config. I have this error and resolved by this code

 var connectionInfoResponse = await Http.PostAsJsonAsync<SignalRConnectionInfo>("http://localhost:7071/api/negotiate", null);
        var connectionInfo = JsonSerializer.Deserialize<SignalRConnectionInfo>(awaitconnectionInfoResponse.Content.ReadAsStringAsync());

        _hubConnection = new HubConnectionBuilder()
            .WithUrl($"{connectionInfo.Url}&access_token={connectionInfo.AccessToken}", (config) => {
                config.AccessTokenProvider = () => { 
                    return Task.FromResult(connectionInfo.AccessToken); 
                };
            })
            .Build();

The 3.1.4 version of the client will have a fix for the access token, so you won't need to hack it into the url.

@BrennanConroy : Which package 3.1.4 ?
I am using Microsoft.AspNetCore.SignalR.Client 3.1.3. I do not see 3.1.4 in https://www.nuget.org/packages/Microsoft.AspNetCore.SignalR.Client

3.1.4 of Microsoft.AspNetCore.SignalR.Client, it's not released yet.

Thanks for the info.

@BrunoBlanes as far as your solution is concerned, I don't see why you'd have any issues with the .NET client accessing a SignalR service endpoint to receive messages. The doc you referenced on the SignalR Service's REST API is your way to hit SignalR without using Functions, so the diagram you posted - if you're using the SignalR Service's REST API you don't need to worry about the Function implementation as you're bypassing it. I just wanted to make this was clear.

So when your clients are connected and your service is pinging the Azure SignalR Service's REST API call, your clients should be able to receive the pings from the service side.

If this isn't helpful, please let us know (and ping me in your reply) and we'll try to support further. Also adding @chenkennt from the service team as an FYI in case he has other thoughts or guidance.

@mkArtakMSFT AFAICT, we don't have anything actionable on this one. Recommend we close.

@bradygaster Thanks, I will look into using SignalR again soon, I've changed focus for now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davisnw picture davisnw  Â·  3Comments

royshouvik picture royshouvik  Â·  3Comments

AnthonyMastrean picture AnthonyMastrean  Â·  3Comments

Rick-Anderson picture Rick-Anderson  Â·  3Comments

YeyoCoder picture YeyoCoder  Â·  3Comments