0

I know it seems a duplicate question from this thread Is it possible to call a SignalR Hub from Postman, but I already know that it is possible, after Postman version > 8.0 using WebSocket Request block. But I can not find any good example of how to do it.

I can connect to my hub via Postman, just by passing the hub Url like this:

enter image description here

But I don't know how can I call the hub method and pass the parameters. Currently, my client program.cs code calls

await hubConnection.InvokeAsync("GetTrades", _username);

and my connection.On:

hubConnection.On<Trade>("ReceiveTrades", (trade) =>
{
    var tradeAsJson = JsonConvert.SerializeObject(trade);
    Console.WriteLine($"Trade received: {tradeAsJson}");
});

How it would be to represent this calls from postman?

2 Answers2

0

I create a sample project with signalR, you can download it from github. We can open site with https://localhost:44381.

Tips: please replace SignalR_ConnectionString in appsettings.json.

enter image description here

And if we want connect to signalR hub, we can use postman, you can follow the steps like below picture.

enter image description here

enter image description here

use wss://localhost:44381/chatHub.

enter image description here

enter image description here

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • 2
    But how can you call your server method? That's the point. I can also connect to my hub, but I can not call my method "GetTrades", passing a username (string) as a parameter – Gabriel Ribeiro Sep 30 '21 at 13:23
  • https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/docs/specs/HubProtocol.md#json-encoding – Anton Toshik Oct 07 '21 at 22:30
0

After establishing the connection put this object in the "Message" area and hit send:

{"arguments":["username", "token"],"invocationId":"0","target":"Your Method","type":1}
  • arguments: include all your parameters here.
  • target: put the method name you want to call
Aziz
  • 1
  • 1