wpf 在带有 .net 4.5 客户端的 Windows 7 上使用 WebSocket 的最佳方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24637127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The best way to use WebSocket on windows 7 with .net 4.5 client
提问by Crossman
I need to make full duplex connection between server and client. Currently I have .net 4.5 wpf client. My initial thoughts was about wcf service with netTcpBinding. But it seems to be working only on windows 8. And client app has to be launched on windows 8.
我需要在服务器和客户端之间建立全双工连接。目前我有 .net 4.5 wpf 客户端。我最初的想法是关于带有 netTcpBinding 的 wcf 服务。但它似乎只能在 windows 8 上运行。客户端应用程序必须在 windows 8 上启动。
I but I'd like to support windows 7 at least. I saw alternative in SignalR, but it will use server-sent events and I'm not sure in it.
我但我想至少支持 Windows 7。我在 SignalR 中看到了替代方案,但它将使用服务器发送的事件,我不确定。
Is it better to make web client with js connection to service? According to http://caniuse.com/websocketschrome and firefox supports it for a long time. If so can I host wcf service with websockets and connect to him from js? I'm wondering why browser supports it and in same time wpf doesn't...
使用 js 连接到服务使 Web 客户端更好吗?根据http://caniuse.com/websocketschrome 和 firefox 支持它很长时间。如果是这样,我可以使用 websockets 托管 wcf 服务并从 js 连接到他吗?我想知道为什么浏览器支持它,同时 wpf 不......
Also performance for connection is not last thing, it should real fast.
连接性能也不是最后一件事,它应该很快。
采纳答案by Aelphaeis
Looking at your question, I do not believe that netTcpBinding is the best choice for this. If I where you I'd use this binding: binding http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding(v=vs.110).aspx
看着你的问题,我不相信 netTcpBinding 是最好的选择。如果我在哪里你我会使用这个绑定:绑定http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding(v=vs.110).aspx
That binding is SOAP so you're likely to get better compatibility and it is designed specifically for duplex connections.
该绑定是 SOAP,因此您可能会获得更好的兼容性,并且它专为双工连接而设计。
As for SignalR and js connection to service I would say at this point you seem to have a working solution and changing the binding is probably a short solution; however, only you can really know for sure.
至于 SignalR 和 js 与服务的连接,我会说此时您似乎有一个可行的解决方案,更改绑定可能是一个简短的解决方案;但是,只有您才能真正确定。
I don't think you need this; however, just in case here is an example of using duplex over wcf. (I used TcpNamedPipe in this example instead of WSDualHttpBinding; however, you only need to make minor changes to get the desired result)
我认为你不需要这个;但是,为了以防万一,这里有一个在 wcf 上使用双工的示例。(我在这个例子中使用了 TcpNamedPipe 而不是 WSDualHttpBinding;但是,你只需要做一些微小的改变就可以得到想要的结果)
回答by Allan Elder
WebSockets are a technology for allowing bidirectional comms over a single TCP connection. It is intended to be used between browsers and webservers, but that doesn't mean you can't use it in other platforms.
WebSockets 是一种允许通过单个 TCP 连接进行双向通信的技术。它旨在用于浏览器和网络服务器之间,但这并不意味着您不能在其他平台上使用它。
There is a C# WebSocket client out there on GitHub (also on NuGet) that you could use to experiment with.
GitHub 上(也在 NuGet 上)有一个 C# WebSocket 客户端,您可以用来进行试验。

