Can not debug my Hub method after upgrading to Sig

2019-08-16 01:48发布

I just upgraded to SignalR 1.0.0-Alpha2. After i did it, I can not debug my hub methods. It never reaches to the breakpoint.

here is code

Reference:

  <script src="../../Scripts/jquery.signalR-1.0.0-alpha2.min.js" type="text/javascript"></script>
<script src="<%:Url.Content("~/signalr/hubs")%>" type="text/javascript"></script>

Client:

$(document).ready(function () {
    con = $.connection.messagingHub;


    $.connection.hub.start(function () {
        var myClientId = $.connection.hub.id;

        con.connectToHub('<%:ViewBag.rid%>', myClientId); // Breakpoint never reaches to this method on the hub.

        con.getWaitingOrdersCount('<%:ViewBag.rid%>').done(function (data) {
            console.log(data);
        });
    });

Hub code:

public void ConnectToHub(Int32 rId, string connectionId)
    {
        var res = new HubConnection();
        res.ConnectionId = connectionId;
        res.RestaurantId = rId;

        dc.HubConnection.AddObject(res);
        dc.SaveChanges();
    }

what may went wrong?? any help??

EDIT:

firebug says:

TypeError: con is undefined 

con.connectToHub('36', myClientId);

1条回答
Viruses.
2楼-- · 2019-08-16 02:06

You must have at least 1 client side function (before start) in order to communicate with the hub. AKA con.client.foo = function....

Secondly ensure that your hub name is one of the following:

public class messagingHub

public class MessagingHub

HubName("messagingHub")
public class foo

Third, when calling functions on the server side you must use the .server method. AKA

con.server.connectToHub(...my arguments...);
查看更多
登录 后发表回答