I have SignalR Hub written in .Net Framework and self-hosted using Owin/Katana.
Now I want to connect the aforementioned Hub in a .Net Core Blazor Web server app,
The problem is in Blazor I have to provide a URL, but Owin/Katana hosted hub does not have a URL to provide.
hubConnection = new HubConnectionBuilder()
.WithUrl(???)
.Build();
In .Net Framework I can connect using,
var connection = new HubConnection("http://localhost:8081/");
var testHub = connection.CreateHubProxy("MyHub");
How can I connect to the same Hub using Blazor Web server app?
Related
I'm trying to authorize a Xamarin Forms app to communicate with a SignalR hub in a ASP.NET Core Blazor Server app with Azure AD B2C configured. Login functionality in Xamarin Forms as well as in ASP.NET Core Blazor Server app is working fine with Azure AD B2C, but I'm not able to use [Authorize] on SignalR hub. I have tried to pass access token received from Azure AD B2C to HubConnectionBuilder as follows.
connection = new HubConnectionBuilder().
WithAutomaticReconnect().
WithUrl(Location + Name, options => { options.AccessTokenProvider = () => Task.FromResult(AccessToken); }).
Build();
Adding following to Startup.cs in ASP.NET Core Blazor app solved the issue. I also used this authentication scheme to authorize the SignalR hub.
.AddAzureADB2CBearer(options => Configuration.Bind("AzureAdB2C", options));
I have a server running .net 4.5.1 with SignalR (IIS)
I want to connect to the server using a console client app on .net core 2,2. I have installed the below Nuget package on the client
Microsoft.AspNetCore.SignalR.Client;
and have followed
https://learn.microsoft.com/en-us/aspnet/core/signalr/dotnet-client?view=aspnetcore-2.2
I keep getting the below error
"There was an error opening the connection:System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found)."
The name of my Hub on the server is correct so I'm not sure of the problem
I have also tried
.WithUrl("http://172.10.0.20:81/client/?hub=myHub")
please help
connection = new HubConnectionBuilder()
//.WithUrl("http://172.10.0.20:81/client/?hub=myHub")
.WithUrl("http://172.10.0.20:81/myHub")
.Build();
connection.StartAsync().ContinueWith(task => {
if (task.IsFaulted)
{Console.WriteLine("There was an error opening the connection:{0}",
task.Exception.GetBaseException());}
else
{Console.WriteLine("Connected");}}).Wait();
connection.StartAsync();
I can't reproduce your problem . But since your server is hosted on .net 4.5.1 , please make sure that you are using same version of SignalR both on server side and client side .
That means that you you cannot use the ASP.NET CORE SignalR (Hub or Client) with the ASP.NET SignalR (Hub or Client). You can't mix them. You can click here for more info .
thanks that pushed me in the right direction.
I'm using signalR with webforms so the hub is located at
http://172.10.0.20:82/signalr/myHub
After changing path I got the below informative error
There was an error opening the connection:System.IO.InvalidDataException: Invalid negotiation response received. ---> System.InvalidOperationException: Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server.
i have a Aspnet core web application ,
want to connect to asp net core signalR server that is in the another server
with different url , in controller .
You can use ASP.NET Core SignalR .NET Client.
This library lets you communicate with SignalR hubs from .NET apps.
We have a SignalR service that runs as a self-hosted OWIN app with Web API 2. It is configured like
resolver.Register(typeof(JsonSerializer), () => JsonSerializer.Create(serializerSettings));
app.MapSignalR(new HubConfiguration { EnableDetailedErrors = true, Resolver = resolver});
We want to replace our JsonSerializer with MessagePack. The obvious examples all configure it from a AspNet.Core web application context. I can't seem to find any examples with Owin self hosting.
EDIT: It looks like MessagePack is a new ASP.NET Core feature. We are running the older ASP.NET version and so I guess the real question is how to do binary formatting over ASP.NET SignalR.
It's not possible. I am migrating my solution to the AspNetCore version of SignalR.
I have a full-working ASP.NET MVC application (.NET Core, ASP.NET Core) which runs fine in Visual Studio (which uses IISExpress).
I would now like to have a console application which takes the ASP.NET Core application and hosts it (self hosting).
Is it possible to self-host an ASP.NET Core Application without IIS?
Yes. In fact, all ASP.NET Core applications are self-hosted. Even in production, IIS/Nginx/Apache are a reverse proxy for the self-hosted application.
In a reasonably standard Program.cs class, you can see the self-hosting. The IISIntegration is optional - it's only necessary if you want to integrate with IIS.
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Yes,ASP.NET Core supports the Open Web Interface for .NET (OWIN),your have two options to host your Asp.net core web application:
IIS
Self-Host
But,self-hosting web application can't restart automatically on system boot and restart or in the event of a failure.
YES
ASP.NET 5 is completely decoupled from the web server environment that hosts the application. ASP.NET 5 supports hosting in IIS and IIS Express, and self-hosting scenarios using the Kestrel and WebListener HTTP servers. Additionally, developers and third party software vendors can create custom servers to host their ASP.NET 5 apps.
more info: ASP.NET documentation - Servers