signalr-tester icon indicating copy to clipboard operation
signalr-tester copied to clipboard

How to pass a query string when connecting new clients?

Open ali-h2010 opened this issue 5 years ago • 6 comments

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?

ali-h2010 avatar Jun 09 '20 08:06 ali-h2010

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

ali-h2010 avatar Jun 10 '20 06:06 ali-h2010

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.

debashish2014 avatar Oct 28 '20 08:10 debashish2014

@ali-h2010 Can you send me how you made to solve this issue. even if hard coded.

hsulipe avatar Jan 21 '21 20:01 hsulipe

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)

ali-h2010 avatar Jan 22 '21 01:01 ali-h2010

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 avatar Jan 22 '21 12:01 hsulipe

@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.

ali-h2010 avatar Jan 22 '21 15:01 ali-h2010