Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass a query string when connecting new clients? #3

Open
ali-h2010 opened this issue Jun 9, 2020 · 6 comments
Open

How to pass a query string when connecting new clients? #3

ali-h2010 opened this issue Jun 9, 2020 · 6 comments

Comments

@ali-h2010
Copy link

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
Copy link
Author

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.

var connection = new HubConnection(argument.Url);

@debashish2014
Copy link
Collaborator

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.

@hsulipe
Copy link

hsulipe commented Jan 21, 2021

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

@ali-h2010
Copy link
Author

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)

@hsulipe
Copy link

hsulipe commented Jan 22, 2021

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

@ali-h2010
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants