Using SignalR client through a web proxy - signalr

I am using the SignalR .NET client library to create a console app/win service to connect to a signal R Hub using HTTPS on the web. Some of these clients may require a web proxy to access the internet. Where/How do I set the web proxy for the SignalR client?
How on earth is this not a real Question guys? I cant get the signalR to connect to the web server hub when the client is behind a firewall/TMG proxy server.

Use Connection.Proxy property for that - https://msdn.microsoft.com/en-us/library/microsoft.aspnet.signalr.client.connection.proxy(v=vs.111).aspx
Example:
var hubConnection = new HubConnection(url);
var webProxy = new WebProxy(new Uri(“address”));
webProxy.Credentials = new NetworkCredential(“Username”, “Password”);
hubConnection.Proxy = webProxy;

Try this:
var webProxy = new WebProxy(new Uri(proxyUrl));
var connection = new HubConnectionBuilder().WithUrl("signalR hub endpoint", h => h.Proxy = webProxy).Build();

In fact we implemented signalr to have a kind of real time progress about some document generation.
Some of our customers couldn't create documents any more because the connection disconnected.
"Maybe" because of some proxy server who not really blocked but hold the request for a while to scan it, so that signalr client got a timeout

Related

How to send Telemetry data from custom end point to azure application insight

I am working with WPF application with client server architecture we not provide internet for client machines so i implemented application telemetry in client WPF application with custom end point and it will send to our local server (on-premise) now i want to send this telemetry data into azure cloud(server have internet connection)
Depending on what language/platform your on-premise server application is written with, you can pick up the corresponding Application Insights SDK and write custom code using TelemetryClient to send telemetry to application insights.
UPDATE on follow up:
At the client end, you can serialize the whole telemetry object like below and then POST to your custom endpoint.
var traceTelemetry = new TraceTelemetry("test message", SeverityLevel.Critical);
traceTelemetry.Context.Cloud.RoleInstance = "test";
var traceTelemetrySerialized = JsonConvert.SerializeObject(traceTelemetry);
Then you can deserialize at the service end and then send to AI:
var traceTelemetryDeserialized = JsonConvert.DeserializeObject<TraceTelemetry>(traceTelemetrySerialized);
telemetryClient.TrackTrace(traceTelemetryDeserialized);

SignalR and switching servers and connection lost

SignalR is running on a certain Server with an open connnection. If we need to bring up another server, then take the original down does SignalR automatically reconnect with the NEW server and start functioning like it was on the first?
We had a similar problem and what we discovered was that SignalR does not automatically reconnect with the new server. Our solution to was to not use the generated proxy. We used an intermediary endpoint whose job it is to provide the current url to use. To connect to SignalR our flow calls the endpoint gets the result using that result we connect to that server for SignalR then when the SignalR connection closes or is lost we repeat the process again as if for the first time.
async function reconnect(connection){
const signalRUrl = await request('<<our intermediary url>>');
connection.hub.url = signalRUrl;
connection.start();
}
var connection = $.hubConnection();
var hubProxy = connection.createHubProxy('yourHub');
hubProxy.on('message',function(){});
await reconnect(connection);
connection.onClose(function () {
reconnect(connection);
});

SignalR JavaScript client API call connection

As a new to ASP.NET environment and SignalR. I am trying to connect a JavaScript client (WebPage) to an API that includes SignalR HUB (developed using WEB.API 2) using only API Calls.
In other words, I just want to do API call to find my client connected to the signalR hub :
/*Instead of doing this*/
var connection = $.hubConnection();
connection.url = "https://www.myAPI.com/signalr/hubs";
var ClientHub = connection.createHubProxy('clientHub');
connection.start()
.done(...).fail(...);
/*I want to do the following*/
$.post( "https://www.myAPI.com/api/ConnectHUB", someClientData)
.done(...).fail(...);
Is that even possible with simple signalR tools ? or I have to implement something sophisticated myself (With websockets, long pooling and everything I read about) ?

SignalR fails to send message to a group when running through LoadBalancer

In order to send SignalR message to a specific user I create a Group for each user upon connection
public override Task OnConnected()
{
log.DebugFormat("Connected. Connection Id = {0} UserId = '{1}'", Context.ConnectionId, UserHelper.UserId);
Groups.Add(Context.ConnectionId, UserHelper.UserId);
return base.OnConnected();
}
Now when a message comes in I send it a group in the following way:
var hubContext = GlobalHost.ConnectionManager.GetHubContext<AlertsHub>();
foreach (var recipient in recipients)
{
hubContext.Clients.Group(recipient).broadcastAlertMessage("Group", msg);
}
That works fine when deployed to a server, but for some reason not working when i access the server through our company load balancer (Citrix Netscaler SDX 11500) but eventually hitting the same sole box.
There is no issue sending messages to all clients
hubContext.Clients.All.broadcastAlertMessage("All", msg);
Also i can keep the connection IDs internally and send messages to a specific client works
hubContext.Clients.Client(AlertsHub.UserToConnectionIdDict["admin"]).broadcastAlertMessage("trageted client", msg);
Why "Group" message doesn't work?
By default, a SignalR server is only aware of and will only send messages to clients connected directly to itself. This is because each SignalR server manages its own messages using its own message bus. Without special configuration, SignalR has no way to know there are other clients connected to a different SignalR server at the same global address.
Fortunately SignalR has scaleout providers that allow you to configure all your SignalR servers in such a way that they can communicate with each other by sharing single message bus.
This "Introduction to Scaleout in SignalR" should provide you with the info you need to get SignalR working properly behind a load balancer: http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-in-signalr

SignalR in Windows app

Please, could anybody show an example how to implement signalR in windows app.
i need to show a message box when server side is started
thnx a lot
Start method of the connection is an asynchronous method. You have to call ConinueWith method of the Task class.
var connection = new HubConnection("http://localhost:port-no");
IHubProxy hub = connection.CreateProxy("hub-name");
connection.Start().ContinueWith((t) => { MessageBox.Show("Your-message"); });

Resources