How to start another SignalR connection based on another one - signalr

I'm using a javascript web app which was connecting through SignalR to aspnet core service A, residing in a docker container. I have to add another service B as a middle between the 2. My guess was that I should split the SignalR connection in 2: first between javascript web app and service B, and second between service B and service A.
So far SignalR works between javascript web app and service B. While service B message arrives at service A, service A answer doesn't receive response from service B (for negotiation of the transport).
In service B I get 404 error, and in service A I see ws-connection time out.
This is what I did in service B:
targetUrl = serviceA_signalR_Url + javascript_app_request_query_string
_connection = new HubConnectionBuilder()
.WithUrl(targetUrl, options => {
{
options.Transports = HttpTransportType.WebSockets;
})
.Build();
_connection.StartAsync.Wait();

Funnily it was my fault. I was trying to use id parameter in the query string. It worked once I removed it

Related

Cannot get MassTransit response after successfully initiating request

I am implementing request/response with MassTransit and Amazon MQ. The (.NET 6 WebApi) host is configured like:
services
.AddMassTransit(x =>
{
x.AddConsumer<ConfigurationConsumer>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host(new Uri($"amqps://{rabbitMqSettings.Host}:{rabbitMqSettings.Port}/{Uri.EscapeDataString("/vhostname")}"), h =>
{
h.Username(rabbitMqSettings.Username);
h.Password(rabbitMqSettings.Password);
});
cfg.ConfigureEndpoints(context);
});
x.AddRequestClient<IConfigurationCommand>();
})
.AddMassTransitHostedService();
The client uses the same configuration without x.AddConsumer() and cfg.ConfigureEndpoints(context).
The problem is: calling GetResponse on the client will successfully execute the consumer on the host which seems to respond as intended, but the client never gets a result and times out.
On the other hand, when I am using a web api controller on the same host to initiate GetResponse, everything works as expected.
Ensure that the message types between the host and the client applications are the same.
ALSO, make sure the bus is started on the client using the hosted service or otherwise.

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);

HttpClient.GetAsync works with LocalHost API, but not Live API

I have a .Net 4.5.2 WebApp that is calling my API. When I point my web app to the LocalHost version of my API, it gets the data, and comes back just fine. I published that API, and confirm that the API is working correctly with PostMan.
Then I run the exact same WebApp code, changing only the URI from localhost to live api, and I get a multiple exception error consisting of the following:
An existing connection was forcibly closed by the remote host
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
The underlying connection was closed: An unexpected error occurred on a send.
An error occurred while sending the request.
Here's my calling code
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("user", serializedUser);
response = null;
try
{
//Uri uri = new Uri("https://jsonplaceholder.typicode.com/posts/1");//https works
Uri uri = new Uri("https://api.acme.com/values/test");
//Uri uri = new Uri("http://localhost/5000/values/test"); //http localhost works
response = client.GetAsync(uri).Result;
}
catch (Exception e)
{
string er = e.Message;
}
}
EDIT 1: I created a .NET Core app from scratch, and my original code works perfectly calling my live API. My original code also work in .NET 4.5.2 calling a different "https" API.
EDIT 2:
So this is where I'm at now, I have created two generic apps from VS 2015, one is a .NET Core Web App, the other a .NET Framework Web App. I have used the above code exactly the same in both apps to call the API. In both apps, I can call a generic "https" api I found online (jsonplaceholder). I can also call the localhost version of my app at "http" from both. In the .NET Core version of the app, I can call my "https" live API and get the results I'm looking for. In the .NET Framework app I still get the same errors.
I can't figure out what the difference is between my Core and Framework requests that is getting one shut down when the other isn't.
It seems you are hosting the application on secured http environment (https). Are you using SSL certificate on the server where you are hosting your Web API? If not, It might be throwing the certificate related exceptions.
Just add the following line before the call to GetAsync and This will ignore the SSL errors.
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
This is only recommended in an intranet environment or other closed network where server identities can't be forged.
C# Ignore certificate errors?
Adding the following line before my API call fixed the issue, but I'd love to hear an explanation of what this line does, and any security risks this might impose using it in my web app.
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Props to this answer!

get signalr hub endpoint url in asp.net mvc (where hub is hosted)

I have an asp.net mvc 5 web app that hosts my signalr (v2) hub/server. This web app kicks off a console app that needs to connect to the hub. How can I get the full url to my signalr hub from within the web app so that I can pass it as an argument to my console app?
Or is there a better way for my console app to know what the url of the hub is?
Thanks!
The answer I was looking for is:
string hubUrl = string.Format("{0}://{1}{2}signalr", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));
The "signalr" part of the string is the default path to your endpoint. If you changed the default endpoint path, then you need to update that part of the string.

Using SignalR client through a web proxy

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

Resources