JavaScript Client – Communicating with WCF Server Using WebSockets

javascriptsoapwcf

I'm excited about the possibilities for duplex communication with WebSockets between a web browser and web server. I see that WCF for .NET 4.5 supports a WebSockets binding now, and I know there's a JavaScript API for using WebSockets. However, what I don't understand is how these are supposed to interoperate. Yes, you can deal with raw message passing with the JS API, but there doesn't seem to be any JS library for doing SOAP-based RPC compatible with WCF.

Do any of you know if there are any libraries to enable a web browser to call a WCF service using WebSockets?

Best Answer

SignalR has a JavaScript API. SignalR helps build asynchronous scalable web applications with real-time persistent long-running connections. Scott Hanselman wrote a great blog post about this.

If that's not your speed, you may be looking for something more like WCF Support for jQuery, which seems to have sprung up from the old WCF-RIA jQuery client. Looks like this will be part of ASP.NET MVC 4. The wiki page for this project seems to indicate that its flexible enough to plug in to WebSockets.

I'm a little concerned about WebSockets in the near term. There are some questions about just how Internet infrastructure (particularly in corporate environments where proxy servers are common) will handle WebSockets. I believe SignalR has strategies to help mitigate this by negotiating fallbacks when WebSockets don't work. Scott Hanselman has another blog post about this which makes some good points in this direction.