I want to open webSocket
by web api post request.
I tryed to use HttpContext.Current.AcceptWebSocketRequest
but it didn't work (as you can see in the following example) because HttpContext.Current
is null in self host.
public class ChatController : ApiController
{
public HttpResponseMessage Get(string username)
{
HttpContext.Current.AcceptWebSocketRequest(new ChatWebSocketHandler(username));
return Request.CreateResponse(HttpStatusCode.SwitchingProtocols);
}
}
Is there a way to get the current http context without IIS
?
Or what is the best way to open websocket?