1
votes

I’m new to ASP.NET Core and SignalR and, of course, experimenting a lot, using Visual Studio Professional 2017.

I have a MVC application with .NET Core 2.1 using NuGet packages Miccrosoft.NETCore.App and Microsoft.AspNetCore.App. I added integrated SignalR support in the source code, as specified in all documents I read, e.g.

  • services.AddSignalR(); in Startup.ConfigureServices and

  • app.UseSignalR(hubRouteBuilder => {hubRouteBuilder.MapHub<MessageHub>("/MessageHub");}); in the method Startup.Configure.

I also added and implemented the client side javascript of the web app and created my MessageHub class.

I built a simple Windows application (IWinForm), built on .NET Framework 4.7.2, using the same implementation taken from an example of a WPF app found on the web that’s working perfectly with my web app, integrated the same Microsoft.AspNetCore.SignalR.Client package (V 1.0.3) as in the WPF into the windows client, and everything works fine when connecting to the web app that hosts the hub connection. With my windows client, I can send message back and forth between both web app and windows app perfectly, even using two different “message receiver”, each implemented in its own app. As I said, everything’s ok

Now my next step is to do the same but using a Windows Service application as client, so I created a Windows Service application, built on the same framework as my WinForm client ( .NET Framework 4.7.2). Then, I reproduced exactly the steps implemented in the windows app, such as using the same package version used in the windows app, building the connection, connection.On etc. exactly as I did in the windows app but it does not connect to the web app. I told myself that a windows service’s state is not “running” as long as the override OnStart is not completed, so I implemented a specific method StartService, called from the override like this: Task.Run(() => StartService()); and, in order to connect to the web server’s hub after the service is properly started and running, I set a timer to be triggered after 10 seconds to run connection.StartAsync(); Unfortunately, unlike the Windows application, the connection to the web hub is not completed (watched using WireShark), therefore no messages are exchanged.

I tried to find a way to know if the connection is successful within the windows service, such as a connection state on the hub connection in C#, but I did not find how.

I’d have many questions, such as should I upgrade my SignalR Client, or something like this, but my main question remains: why the pattern successfully used in the windows app works but the same pattern does not in windows service?

Any suggestions are welcome, thank you very much for your help.

1

1 Answers

1
votes

After many tries, I finally discovered that when my Windows Services was attempting to connect to the SignalR server, this one was launched in SSL. Therefore, without any certificate, the service was not able to connect and was receiving an HttpRequestException, from which I found my problem. As soon as I removed the SSL from the Web host app, it started to work fine. I still have some questions in my mind such as: why my Windows Form app connects without problem under SSL but the Windows service doesn't. If anyone can explain me, it would be appreciated. Thanks in advance. Pierre