signalr-tester
signalr-tester copied to clipboard
How to pass a query string when connecting new clients?
I need to pass a query string when connecting such as:
new HubConnection(URL , "id=" + EmployeeID)
Can you please guide me on how to do that?
I noticed that the client doesn't take any arguments for query parameters. I will hard code it for now for my testing but it can be part of the agent to pass query string paramters.
https://github.com/emtecinc/signalr-tester/blob/7936f8f041504c18b39ab1d3de2ad8be85c5d1c3/SignalR.Tester.Core/Clients/SignalRClient.cs#L78
Hi @ali-h2010 Thank you. Yes, it can be part of agent to pass the query string parameters. I will do the required changes and will be available in next release.
@ali-h2010 Can you send me how you made to solve this issue. even if hard coded.
just add a parameter after the url. The trick is that, if you want to add multiple parameters, you need to add '&' before each one so it looks like an actual URL query string
Ex:
var connection = new HubConnection(argument.Url, "id=" + UserId + "&name=" + UserName)
I tried this:
public async Task CreateAndStartConnection(ConnectionArgument argument, Tuple<string, Func<string, Task<object[]>>> methodToInvoke = null)
{
var connection = new HubConnection(argument.Url + "?Id=" + clientId);
proxy = connection.CreateHubProxy(argument.Hub);
this.connection = connection;
token = new CancellationTokenSource();
this.connection.Closed += OnClosedInternal;
for (int connectCount = 0; connectCount < 2; connectCount++)
{
if (!token.IsCancellationRequested)
{
try
{
await this.connection.Start(GetTransportType(argument.Transport));
if (methodToInvoke != null)
await InvokeMethod(methodToInvoke.Item1, methodToInvoke.Item2);
break;
}
catch (Exception ex)
{
OnLogMessage?.Invoke(new EventMessageInfo("Failed to create connection. Will attempt to reconnect...", MessageType.Error));
logger.Error(ex);
}
await Task.Delay(1000);
}
else
break;
}
}
the thing is since this is an external class outside my project I have no idea how to pass a different Id for each new connection as a parameter to this function CreateAndStartConnection
@hsulipe , you need to add some logic in LoadTestFlow class to add an extra question to the load test that takes the starting index beside the already existing "How many connections do you want to create".
Once done you need to add some logic in CreateAndStartConnection which is already called in a loop for each connection to append the start index number to the userID and increment it for next call.
It's a lengthy process but you can follow it if you debug the app and follow the flow of the project.