1
客戶是否有辦法來遍歷客戶SignalR遍歷在Signalr
All clients under a hub
All clients under a group
All client a user is connected to
我的目標是一個讓每個環路連接ID和處理他們的。
var hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
var allClients = hubContext.Clients.All;
var clientsOfGroup = allClients.Group(groupName);
我正在嘗試上面的代碼,迭代allClients和clientsOfGroup,都拋出錯誤。
有沒有辦法用SignalR獲得連接ID收集?
編輯:
如果我運行下面的代碼:
foreach (var client in allClients)
{
}
我得到這個異常:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: '不能 類型隱式轉換'微軟。 Asp Net。 SignalR。集線器。 ClientProxy'至 'System.Collections.IEnumerable'。一個顯式轉換存在(被 缺少強制轉換?)」
,如果我運行此:
foreach (var client in clientsOfGroup)
{
}
我得到以下異常
> Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to
> 'System.Collections.IEnumerable'. An explicit conversion exists (are
> you missing a cast?)'
_ 「兩者都引發錯誤」 _ - 你爲什麼不告訴我們的錯誤是什麼。 – stuartd
請分享此處的例外 –
編輯例外 – Raghav