Html – Confused by Microsoft WebSockets namespaces

htmlnetwcfwebsocket

So far, in tutorials, blogs, and official documentation, I've seen:

  • Microsoft.Web.WebSockets
    • Obtained from NuGet
    • The assembly is Microsoft.WebSockets, but the Namespace is Microsoft.Web.WebSockets
    • Last updated 14 Sept 2011
    • Contains WebSocketHandler, WebSocketCollections, WebSocketExtensions
  • System.Web.WebSockets
    • Part of .NET 4.5 and available in Visual Studio 11 Developer Preview
    • Contains AspNetWebSocket, AspNetWebSocketContext, AspNetWebSocketOptions classes
    • Documentation on MSDN
  • System.Net.WebSockets
    • Thanks Ladislav Mrnka for pointing this one out
    • Part of .NET 4.5 and available in Visual Studio 11 Developer Preview
    • Contains WebSocket, HttpListenerWebSocketContext and more
    • Documentation on MSDN
  • System.ServiceModel.WebSockets
    • I must have imagined I'd seen this one somewhere, can't find it now
  • Microsoft.ServiceModel.WebSockets
    • Obtained from html5labs.interoperabilitybridges.com/….
    • Installed into [Program Files]\Microsoft SDKs\WCF WebSockets\11.06.22\bin
    • Contains WebSocketHost, WebSocketService, WebSocketsService classes, plus interfaces and collections
    • Last updated 22 June 2011

are these somehow different? Are some older versions?

I've always assumed the 'Microsoft.Web' namespace was used for pre-release code, but even the demos at the Build conference use this namespace, despite the fact that .NET 4.5 includes the System.Web.WebSockets namespace built in.

System.Web.WebSockets seems to have the same API as Microsoft.Web.WebSockets, but with classes and methods prefixed with AspNet.

System.ServiceModel.WebSockets is part of the WCF namespace, which also seems a sensible place to put this stuff.

Help – I'm confused. What should I be using?

Best Answer

I will add little bit more to your confusion. Microsoft.* prefixed assemblies / namespaces are usually either very specific to some language or not part of .NET framework (shipped out of band (or prototypes)).

Assemblies / namespaces shipped with .NET framework usually start with System.*. There are two namespaces containing features related to WebSockets in .NET 4.5:

  • System.Net.WebSockets - implementation of WebSockets
  • System.Web.WebSockets - integration of WebSockets with ASP.NET

I haven't see System.ServiceModel.WebSockets but I think there was some prototype named Microsoft.ServiceModel.WebSockets