Window Forms Application .NET 4.7.1, Microsoft.AspNetCore.SignalR.Client 1.0.2 NuGet package
I've been trying to get a Windows Forms application client for SignalR running using Azure SignalR Service. I have my SignalR Service provisioned on Azure but when I do the following I get exceptions.
var connection = new HubConnectionBuilder().WithUrl("https://silly.service.signalr.net/messages").Build();
Task.Run(() => connection.StartAsync()).Wait();
The exceptions are:
HttpRequestException: An error occurred while sending the request.
WebException: Unable to connect to the remote server
SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 13.66.198.150:443
The third (SocketException) seems to be the relevant issue but I'm not sure. I haven't had a lot of luck finding good resources for the new Azure SignalR Service beyond the basic ChatSample which
has a client implemented in JavaScript.
Does anyone have suggestions for me either about what to try or perhaps further examples?
As of today, if you want to implement duplex communication between SignalR client and server using Azure SignalR Service, you must need ASP.net Core SignalR Server Hub(Web App). However, If you just want to push the messages from server to clients
(oneway), you can use Azure SignalR Service without having Asp.net Core SignalR Hub (Web App) with REST API url.
In the diagram above, we have two endpoints called Server Endpoint and Client End Point. With those End Points, SignalR Server and Client can connect to Azure SignalR Service without the need of Asp.net Core Web App.
Azure SignalR Service exposed set of REST APIs to send messages to all clients from anywhere using any programming language or any REST client such as Postman. The Server REST API swagger documentation is in the following link.
REST APIs are only exposed on port 5002. In each HTTP request, an authorization header with a JSON Web Token (JWT) is required to authenticate with Azure SignalR Service. You should
use the AccessKey in Azure SignalR Service instance's connection string to sign the generated JWT token.
Rest API URL
POST https://<service_endpoint>:5002/api/v1-preview/hub/<hub_name>
The body of the request is a JSON object with two properties:
Target: The target method you want to call in clients. Arguments: an array of arguments you want to send to clients.
The API service authenticates REST call using JWT token, when you are generating the JWT token, use the access key in SignalR service connection string as a Secret Key and put it
in authentication header.
Clients also connect to Azure SignalR service using JWT token same as described above and each client will use some unique user id and the Client Endpoint URL to generate the token.
Member
2 Points
13 Posts
Issues connecting to Azure SignalR Service using Windows Forms client.
Jul 24, 2018 08:52 PM|Dane R. Vinson|LINK
Window Forms Application .NET 4.7.1, Microsoft.AspNetCore.SignalR.Client 1.0.2 NuGet package
I've been trying to get a Windows Forms application client for SignalR running using Azure SignalR Service. I have my SignalR Service provisioned on Azure but when I do the following I get exceptions.
The exceptions are:
HttpRequestException: An error occurred while sending the request.
WebException: Unable to connect to the remote server
SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 13.66.198.150:443
The third (SocketException) seems to be the relevant issue but I'm not sure. I haven't had a lot of luck finding good resources for the new Azure SignalR Service beyond the basic ChatSample which has a client implemented in JavaScript.
Does anyone have suggestions for me either about what to try or perhaps further examples?
Thanks for any input you might have.
Dane Vinson
Member
60 Points
17 Posts
Re: Issues connecting to Azure SignalR Service using Windows Forms client.
Aug 15, 2018 02:08 AM|vavjeeva|LINK
Hello Dane,
As of today, if you want to implement duplex communication between SignalR client and server using Azure SignalR Service, you must need ASP.net Core SignalR Server Hub(Web App). However, If you just want to push the messages from server to clients (oneway), you can use Azure SignalR Service without having Asp.net Core SignalR Hub (Web App) with REST API url.
In the diagram above, we have two endpoints called Server Endpoint and Client End Point. With those End Points, SignalR Server and Client can connect to Azure SignalR Service without the need of Asp.net Core Web App.
Azure SignalR Service exposed set of REST APIs to send messages to all clients from anywhere using any programming language or any REST client such as Postman. The Server REST API swagger documentation is in the following link.
https://github.com/Azure/azure-signalr/blob/dev/docs/swagger.json
Server Endpoint
REST APIs are only exposed on port 5002. In each HTTP request, an authorization header with a JSON Web Token (JWT) is required to authenticate with Azure SignalR Service. You should use the AccessKey in Azure SignalR Service instance's connection string to sign the generated JWT token.
Rest API URL
POST https://<service_endpoint>:5002/api/v1-preview/hub/<hub_name>
The body of the request is a JSON object with two properties:
Target: The target method you want to call in clients.
Arguments: an array of arguments you want to send to clients.
The API service authenticates REST call using JWT token, when you are generating the JWT token, use the access key in SignalR service connection string as a Secret Key and put it in authentication header.
Client Endpoint
https://<service_endpoint>:5001/client/?hub=<hubName>
Clients also connect to Azure SignalR service using JWT token same as described above and each client will use some unique user id and the Client Endpoint URL to generate the token.
You can find more details in my blog article http://www.jeevasubburaj.com/2018/08/azure-signalr-messaging-with-net-core.html
and i have uploaded the source code in github.