Asp.Net WebAPI WebSockets in stand-alone mode does not work

I am basically trying to make web sockets in webapimyself.

Here is 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.Currentit is always zero. It exists only when hosting through IIS.

My question is how can I make standalone web sockets using webapiif I cannot get the current context.

Thank.

+4
source share

All Articles