Search code examples
javac#asp.net-core-signalr

Send a json object to .net server using signalr and Java client


I am using SignalR 5.0, I am trying to send a JSON from the Android client. I have looked into this. But it's not working for me, the send works I get the json in the test "{"Id":"123123","ReceviedDateTime":"Nov 23, 2020 12:50:55 PM","RepliedDatetime":"Nov 23, 2020 12:50:55 PM"}" but the Pong method is never called. Added services.AddSignalR().AddJsonProtocol(); in the startup

Pong model:

public class PongModel
{
    public int Id { get; set; }
    public int DeviceId { get; set; }
    public string PhoneNumber { get; set; }
    public DateTime SendDatetime { get; set; }
    public DateTime ReceviedDateTime { get; set; }
    public DateTime RepliedDatetime { get; set; }
}

Java code: enter image description here

Methods (.net core 5)

    public void Pong(PongModel pongModel)
    {
    }

    public void Send(string test)
    {
    }

Solution

  • Pass object directly example without serializing: hubConnection.send("Pong", p); Add this to get the binding error: "Microsoft.AspNetCore.SignalR": "Debug", "Microsoft.AspNetCore.Http.Connections": "Debug"