Sunday, June 3, 2018

SignalR Core not generating(mapping) Client methods

Leave a Comment

The SignalR Core is generating Hub proxies script, but not adding the "client" methods. (No errors in server or client - only not working)

Generated JS from <script src="http://localhost/signalr/hubs">

proxies['messageHub'] = this.createHubProxy('messageHub');  proxies['messageHub'].client = { }; proxies['messageHub'].server = {         handleMessage: function (receivedString) {             return proxies['messageHub'].invoke.apply(proxies['messageHub'], $.merge(["HandleMessage"], $.makeArray(arguments)));          }     }; 

Here's the Hub in Server Side:

public class MessageHub : Hub {     public void HandleMessage(string receivedString)     {         var responseString = string.Empty;          MessageHandler.HandleMessage(receivedString, ref responseString);          Clients.All.sendMessage(responseString);      } } 

The sendMessage methos should be included in the messageHub client proxies in the JS file. $.connection.messageHub.client.sendMessage is undefined

Only the handleMessage for server proxies was created (and working).

Here's my StartUp.cs inclusions for SignalR:

ConfigureServices:

services.AddMvc(options =>         {             options.Filters.Add(new RoleFilterAttribute());         }).AddJsonOptions(options => options.SerializerSettings.ContractResolver =                 new DefaultContractResolver()); services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true) 

Configure:

app.UseWebSockets(); app.UseSignalR(); 

project.json:

"Microsoft.AspNetCore.Mvc": "1.0.0-*", "Microsoft.AspNetCore.WebSockets": "1.0.0", "Microsoft.AspNetCore.SignalR.Server": "0.2.0-*", 

SOME ADDITIONAL TENTATIVES:

1 - Change method case in Server Side to see if it's mapped:

Clients.All.SendMessage(responseString); 

Did not work!

2 - Change the client side to dynamic mapping:

var connection = $.hubConnection('http://localhost/'); var proxy = connection.createHubProxy('messageHub'); connection.start({ withCredentials: false }).done(function () { console.log("CONNECTED") }); proxy.on("sendMessage", function (result) {console.log(result);}); proxy.invoke("handleMessage", msg).done(function(result)console.log(result);}); 

Again only the handleMessage (server) worked.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment