c# - SignalR. HubConnection The client method is not invoked from server -
Can someone help me understand
What is wrong with the following code, the client method SignalR Is not implemented by the server method
When the broadcast button is clicked, then I am able to open the client method. And whenever I run the invoke code from a console application, then the event is removed.
The server class lives in a custom event handler in a separate assembly.
The code of the chat hub is as follows:
Namespace MySample.Handler {[Hub ("chat")] Public class chat: Hub {Send public zero (string message ) {Client. Message (message); // I also saw this code as well: // IHubContext reference = GlobalHost.ConnectionManager.GetHubContext & lt; Chat & gt; (); // context.Clients.addMessage ("Hello World"); }}}
The source code for applying the chat hub is as follows:
Namespace MySample.Handler {Public Stable Class SelfInvoke {Public Stable Zero OnEvent ( ) {Var Hub Connection = New Hub Connection ("http: // localhost: 48994"); Var chat = Hub connection. Crete Proxy ("chat"); HubConnection.Start () Wait () .; String message 1 = "On event handler is !!!"; Chat.Invoke ("Send", message1). Wait (); }}}
Index.aspx
& lt; Script src = "scripts / jquery-1.6.4.min.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script src = "script / jquery.signalR-0.5.2.min.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script src = "/ signalr / hubs" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Function () {var chat = $ .connection.chat; chat.addMessage = function (message) {$ ('# messages'). Attachments (' & Lt; Input type = "button" id = "broadcast" value = "broadcast" /> & Lt; Ul id = "message" & gt; & Lt; / Ul & gt;
index.aspx.cs [code behind code]
Secure Zero Page_load (Object Sender, EventEurge E) {Self Invoke .onewind ();
Any help is highly appreciated.
Regards Vince
Change your Javascript client function definitions so that they are:
chat.client.XXX = function ...
instead of:
chat.XXX = function ...
In addition, change your call to the server:
instead of:
chat.send ($ (' $ '($ (' $ Msg ') .msg'). Val ());
Comments
Post a Comment