basically I'm trying to do web-sockets in webapi
in a self-host manner.
Here's an example:
class SomeController : ApiController
{
public HttpResponseMessage SomeAction()
{
if (HttpContext.Current.IsWebSocketRequest)
{
HttpContext.Current.AcceptWebSocketRequest(new SomeSocketHandler());
return Request.CreateResponse(HttpStatusCode.SwitchingProtocols);
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
}
The problem is that HttpContext.Current
is always null.
It only exists when hosting through IIS.
My question is how can I do self-hosted web sockets using webapi
if I can't get the current context.
Thanks.