Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Show .NET Core Server Example #82

Open
hawkerm opened this issue Feb 18, 2019 · 22 comments
Open

Show .NET Core Server Example #82

hawkerm opened this issue Feb 18, 2019 · 22 comments

Comments

@hawkerm
Copy link

hawkerm commented Feb 18, 2019

I want to run a SignalR .NET Core server without an ASP.NET website backing it (like the self-host examples of the old SignalR).

It'd be nice to see an example here of how to do this?

@davidfowl
Copy link
Member

I want to run a SignalR .NET Core server without an ASP.NET website backing it (like the self-host examples of the old SignalR).

ASP.NET Core SignalR is built on ASP.NET Core. ASP.NET Core is self hostable, not sure what you mean. The old SignalR used Katana (which was OWIN based), it has no self hosting story outside of that. The moral equivalent is what already works today.

What exactly are you looking for?

@hawkerm
Copy link
Author

hawkerm commented Feb 18, 2019

Thanks @davidfowl, I guess I'm looking for an example that shows setup from a .NET Core Project process self hosting ASP.NET then vs. starting from a ASP.NET Core project. (i.e. how do I set this up from a new VS project done from .NET Core vs. ASP.NET Core).

@davidfowl
Copy link
Member

Why?

@hawkerm
Copy link
Author

hawkerm commented Feb 18, 2019

I'm trying to setup a server/client relationship from a .NET Core process, and I wanted to leverage SignalR's client from multiple languages to connect to the .NET core server.

@davidfowl
Copy link
Member

You can do that by just making an ASP.NET Core project, I don't understand what you need outside of that.

@hawkerm
Copy link
Author

hawkerm commented Feb 19, 2019

I want the server to be a contained exe vs. needing to be served.

@davidfowl
Copy link
Member

I'm not sure what you mean, you can self host ASP.NET Core applications.

@hawkerm
Copy link
Author

hawkerm commented Feb 19, 2019

I guess I don't know much about the differences between how an exe for .NET Core works and how self-hosting an ASP.NET Core application works?

@davidfowl
Copy link
Member

Ok that makes more sense. ASP.NET Core is basically a console application (unless you’re running in process on IIS). You can get an exe for your ASP.NET Core application

@hawkerm
Copy link
Author

hawkerm commented Feb 20, 2019

Thanks @davidfowl, that's good to know. Is there any info on the extra overhead in terms of dependencies/package-size when using an ASP.NET Core application over a .NET Core application?

@bradygaster
Copy link
Member

Or were you thinking of something like a static site "hosted" using [for example] blobs in a storage account, the HTML of which would just make a connection to a SignalR Hub hosted somewhere (in an EXE, the Azure SignalR Service, whatever), and make use of the SignalR connection as the thing connecting the "website" to the "server?"

@bradygaster
Copy link
Member

NM, looks like your desires are more like the self-host examples we had for OWIN (which as @davidfowl points out are done using things like BackgroundService) or Kestrel-hosted apps. The static-file scenario is another one about which I've been asked.

@tylerhartwig
Copy link

tylerhartwig commented Apr 19, 2019

Is it possible to start a SignalR Core Hub from a console app? It seems like that would be possible according to this thread. My end goal is to setup a hub under a dotnet CLI tool. Is this possible?

If there is another place I should ask about this, I will move my question, here just seemed like the most relevant place.

EDIT:
I assume this is as simple as just building an ASP.NET Core host and calling Run(). Does anyone has any experience with this or know any pitfalls in this?

@davidfowl
Copy link
Member

Sure, add a reference to ASP.NET Core and party on.

@CenturionYun
Copy link

I also encountered the same problem, according to this threads, it seems that we can self host the asp .net core project to work around, but i’m not sure whether asp.net core app can call all windows natives APIs, anyone know this?

@davidfowl
Copy link
Member

Yes you can call native windows APIs when running an ASP.NET Core application on windows.

@CenturionYun
Copy link

Yes you can call native windows APIs when running an ASP.NET Core application on windows.

That's cool! Thanks for your comments.

@devhl-labs
Copy link

An example showing two .net core console apps communicating with SignalR would be fantastic.

@bradygaster
Copy link
Member

@devhl-labs - how about an example in which a microservice (a worker-template app) running in Kubernetes, using the .NET SignalR client, and a second client, being a Blazor web assembly client as outlined in this blog post. if that'd suffice, i'll have a demonstration soon of this working.

@parad74
Copy link

parad74 commented Feb 11, 2020

Thanks for great examples,
But I can’t be sure how to connect Сlient SignalR in WebAPI dotnet Core.
Without Server-SignalR on WebAPI
Where should be do

`hubConnection = new HubConnectionBuilder()
  .WithUrl(NavigationManager.ToAbsoluteUri(SignalRHub.ChatHub))
			   .Build();
	hubConnection.On<string, string>(SignalRHubFunction.ReceiveMessage, (user, message) =>
				{
					var encodedMsg = user + " says " + message;
					messages.Add(encodedMsg);
					StateHasChanged();
				});

				await hubConnection.StartAsync();

as Service in Startup
and then use hubConnection get from DI as Service in controller

or hubConnection = new HubConnectionBuilder() in one per controller
or each call Action in Contoroller createhubConnection = new HubConnectionBuilder()

I'm not sure if it should be one hubConnection, that starts at startup or the only one on the controller or one per Action.

And how to use DI to use

hubConnection.SendAsync("SendMessage", userInput, messageInput)

in the controller / any Action

What are the best practices?
If you ll add a simple example with WebAPI using Client SignalR, that would be great

For example, the Task is : after execute Action in the Controller to send Message to all Client SignalR.

@davidfowl
Copy link
Member

What type of application is it? Are you hosting SignalR in a different application or in the same application as the API?

@parad74
Copy link

parad74 commented Feb 11, 2020

These are 2 applications Server and WebAPI :
My architecture has 1) remote WebAPI application and 2) Server that calls WebAPI. They are located at different addresses and perform different tasks. Hub SignalR is located on Server. I need to configure Client on WebAPI so that it informs everyone about the intermediate steps performed so that the server knows.
The whole day I was looking for how to register Client SignslR as Service (in WebAPI) so that Client SignslR would send messages from Controller on WebAPI to Server (Hub SignslR ).
I would like it to be convenient as with IHubContext, but at least correctly, even if it is not convenient.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants