My WebSocket structure is below.
public HttpResponseMessage Get(int id, string kod)
{
if (HttpContext.Current.IsWebSocketRequest)
{
HttpContext.Current.AcceptWebSocketRequest(new SocketHandler(id, kod));
return Request.CreateResponse(HttpStatusCode.SwitchingProtocols);
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
class SocketHandler : WebSocketHandler
{
DnaEntities db = new DnaEntities();
private static WebSocketCollection Clients = new WebSocketCollection();
private Yonetim_Kullanici Kullanici;
public SocketHandler(int KullaniciId, string OturumKontrolKod)
{
var sorgu = db.Yonetim_Kullanici.Where(k => k.Id == KullaniciId && k.OturumKontrolKod == OturumKontrolKod && k.Durum == 1);
if (sorgu.Count() == 1)
{
Kullanici = sorgu.FirstOrDefault();
}
}
public override void OnOpen()
{
if (Kullanici != null)
{
Clients.Add(this);
}
base.OnOpen();
}
public override void OnClose()
{
Clients.Remove(this);
base.OnClose();
}
public override void OnMessage(string data)
{
foreach (var item in Clients)
{
var data = item.Kullanici
//item.Send();
}
}
As follows, i can send to everyone.
Clients.Broadcast(message);
But, When I want to send one by one:
foreach (var item in Clients)
{
var UserModel = item.Kullanici;
}
Error Message:
'WebSocketHandler' does not contain a definition for 'Kullanici' and no extension method 'Kullanici' accepting a first argument of type 'WebSocketHandler' could be found.
item.Kullanici => as you can see in the picture