SignalR - how to invoke client method from a class in a different assembly? -
Can anyone help me understand
The client method by using the Signal Server server method How to open from
I tried 3 different ways to invoke the law:
I designated my Hub [HubName ("Notification")]
Method 1
Client. Message (message); It may not be in order "to a null reference binding"
Method 2
IHubContext context1 = GlobalHost. ConnectionManager.GetHubContext ("notificationhub"); Context1.Clients.addMessage ('hello'); Customer silent
Method3
var hubConnection = new HubConnection ( "http: // localhost: 21120 /".) ; Var Notification = Hub Connection Crete Proxy ("Notification"); HubConnection.Start () Wait () .; information. Invoke ("send", "hello"). Wait (); This method returns an error: {"Remote server returned an error: (500) Internal server error."} To my surprise, I use this method from the console application The third method I am capable of.
What is the best solution to implement it and the reason for this is that I am not able to implement the client method? Can anyone help me with this?
Regards Vince
Here's how I am, little hack, but This works only when it works by calling the Hub with the controller, otherwise it does not work Use the UpdateHubFromController method.
Public class UpdateFeedActivity: Hub {readonly IHubContext _hubContext; Public UpdateFeedActivity () {_hubContext = _hubContext ?? GlobalHost.ConnectionManager.GetHubContext & LT; UpdateFeedActivity & gt; (); } Public void UpdateFeed (string Names, string Itemid, Enums.FeedActivityTypes activityType, string userId = "", string actionResult1 = "", string actionResult2 = "", string actionResult3 = "") {Clients.Group (Names) .updateMessages ( new FeedHubResponse {Itemid = Itemid, ActivityType = activityType.ToString (), userId = userId, actionResult1 = actionResult1, actionResult2 = actionResult2, ActionResult3 = actionResult3}); } Public void UpdateFeedFromController (string Names, string Itemid, Enums.FeedActivityTypes activityType, string userId = "", string actionResult1 = "", string actionResult2 = "", string actionResult3 = "") {_hubContext.Clients.Group (Names). updateMessages (New FeedHubResponse {Itemid = Itemid, ActivityType = activityType.ToString (), userId = userId, ActionResult1 = actionResult1, actionResult2 = actionResult2, actionResult3 = actionResult3}); } Join Public Zero (string groupname) {Groups.Add (Context.ConnectionId, groupname); }} Public Square FeedHubResponse {public string ItemId {get; Set; } Public String UserId {get; Set; } Public string ActionResult1 {get; Set; } Public string ActionResult2 {get; Set; } Public string ActionResult3 {get; Set; } Public String ActivityType {get; Set; } Public string text {get; Set; }}
Comments
Post a Comment