Last post Nov 24, 2011 08:08 PM by Paul Batum
Nov 24, 2011 10:43 AM|idof|LINK
I'm using Win8, VS 11, and WCF 4.5 to create a simple WebSockets sample, using the demos showed in BUILD.
I noticed that the demo code uses the WebSocketHost.CreateWebSocketBinding which creates a custom binding, whereas the WCF 4.5 documentation says that WebSockets is supported by the NetHttpBinding.
I have tried replacing the factory code with a simple ServiceHost and NetHttpBinding, but the client is not able to connect to the service this way. From what I've seen, the custom binding used by the WebSocketHost uses binary stream encoding element, whereas
the netHttpBinding uses the normal binary encoding of WCF.
How should I initialize the NetHttpBinding so I can use it instead of the WebSocketHost? I want to create a "clean" WCF 4.5 solution that shows how to use WCF's new bindings, not how to create custom bindings through the use of external assemblies.
Nov 24, 2011 02:40 PM|Paul Batum|LINK
Are you using WCF on both your client and server and you just want a traditional WCF experience but using WebSockets as the transport? If so, just use the NetHttpBinding as you would in a normal WCF application (instead of NetTcpBinding, for example). You
don't need a custom factory or custom binding in this case. If you use it with a duplex contract (one that defines a callback contract) the NetHttpBinding will automatically use WebSockets.
If you are not using WCF on the client - if your client is a browser or something else that implements the WebSocket protocol, then you will need to use a custom binding in order to prevent WCF from expecting SOAP messages.
Nov 24, 2011 03:05 PM|idof|LINK
I was using a web browser as a client.
That sounds reasonable. So use a custom binding for browsers and NetHttpBinding for .NET clients instead of WsDualHttpBinding.
Did you mention this in your session? I only browsed the slides, but didn't watch the entire video. If it's there, let me know and I'll check it out.
Nov 24, 2011 08:08 PM|Paul Batum|LINK
It gets a mention in my BUILD talk but we don't go into much detail. If you have any additional questions please ask away!