Reputation: 63
I am trying to create a setup where i have an azure signalr service.
Then i hosts a local server, which is a dotnet core console app which "connects" to the azure signalr service using a connectionstring.
Then i have a client (winforms) which tries to connect to that same azure signalr service using the same connectionstring.
But i get this error: System.UriFormatException: 'Invalid URI: The URI scheme is not valid.' when i try to start the client.
I have create a azure signalr service on the azure portal site.
Then I have create C# dotnet core console application that when it runs it adds the azure signalR service using the connectionstring:
// Add services to the container.
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration.GetSection("AzureAd"));
builder.Services.AddSignalR().AddAzureSignalR(@"Endpoint=<my url>.service.signalr.net;AccessKey=<my accesskey>;Version=1.0;");
var app = builder.Build();
app.MapHub<ChatSampleHub>("/ChatSampleHub");
It runs fine and i see on the azure portal site that a server is up and running, when i fire up my console app.
I have a class ChatSampleHub like this:
public class ChatSampleHub : Hub
{
public Task BroadcastMessage(string name, string message) =>
Clients.All.SendAsync("broadcastMessage", name, message);
public Task SendMessage(string message) =>
Clients.All.SendAsync("MessageReceived", message);
public Task Echo(string name, string message) =>
Clients.Client(Context.ConnectionId)
.SendAsync("echo", name, $"{message} (echo from server)");
}
Now i have created a winforms app that i want to call the chathub and broadcast to all other clients. So far i have this on the client when user clicks on the connect button:
private async void buttonConnect_Click(object sender, EventArgs e)
{
hubConnection = new HubConnection(AzureSignalRConnectionString);
hubProxy = hubConnection.CreateHubProxy("/ChatSampleHub");
hubProxy.On<string>("MessageReceived", message =>
{
// Handle incoming message
// This is just an example; you can update your UI or perform any desired action here
AppendMessageToTextBox(message);
});
try
{
await hubConnection.Start();
MessageBox.Show("Connected to Azure SignalR");
}
catch (Exception ex)
{
MessageBox.Show("Error connecting to Azure SignalR: " + ex.Message);
}
}
The AzureSignalRConnectionString is the same connectionstring i used in my console app. But when I call the await hubConnection.Start(); I get this error: System.UriFormatException: 'Invalid URI: The URI scheme is not valid.'
What am i doing wrong?
Upvotes: 3
Views: 1278
Reputation: 22082
This is Azure SignalR Service workflow.
In your scenario, you have used the azure signalr service connection string in dotnet core console application which should be a web application.
The this console application is the Web App
in my screenshot, and other clients (Javascript or winform(.net core)) should negotiate with this web app and get the security, after that the clients could connect azure signalr service.
Upvotes: 1