signalr收不到服务器的信息,SignalR .NET客户端未收到消息

I have a .NET console application that I am practicing signalR with.

var hubConnection = new HubConnection("http://URL/signalr/");

var hub = hubConnection.CreateHubProxy("Hub");

hub.StateChanged += change =>

{

Console.WriteLine(change.NewState);

};

hub.Received += s =>

{

Console.WriteLine(s);

};

hub.On("processMessage", (group, message) =>

{

Console.WriteLine(message);

});

await hubConnection.Start();

await hub.Invoke("Subscribe", "New group");

I see the state changing from Connecting to Connected but I am not getting a "Received" event on the client when the server sends a message. The server is sending a group message as soon as the client subscribes and I can see the message being sent with the correct "New group" groupname, however I never receive the message on the client. I also do not receive the processMessage event when the server uses that method.

Server Code

private void CallBack(string group, string message)

{

Clients.Group(group).processMessage(group, message);

}

The other method on the server is Subscribe which just sets my inner server to use the CallBack method when it has data available to send to the client.

Edit

This works in Javascript it just doesn't seem to work in the .NET client.

Talk1:

can you please add the server code as well

Talk2:

Why the close votes and downvote? This is a legit question with efforts.

Talk3:

Just added the server code.

Talk4:

Can you put-up your Hub code as well.

Talk5:

+1 for including the rest of your server-side Hub class in your question. If you can't post the code for your entire Hub, you should at least include the code for your Subscribe method.

Solutions1

Without full serverside code it's hard to say but I think this part is wrong

hubConnection.CreateHubProxy("Hub");

as argument you need the name of your hubclass on serverside. For example

hubConnection.CreateHubProxy("MyHub");

To get more informations on clientside why it fails you can temporary add the following to your HubConnection

hubConnection.TraceLevel = TraceLevels.All;

hubConnection.TraceWriter = Console.Out;

After adding this you will get further debuging informations in your output section in VS

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值