WCF两种HTTP通信绕过防火墙 [英] WCF two way HTTP communication to bypass firewalls

查看:159
本文介绍了WCF两种HTTP通信绕过防火墙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用WCF启用双向通信,而无需在客户端上打开端口.

I want to use WCF to enable two way communication without opening a port on the client.

我正在开发类似P2P应用程序(类似于teamviewer/logmein)的东西,您无需打开端口即可进行通信.

I'm developing something like a P2P application (similar to teamviewer/logmein) where you don't need to open ports to communicate.

如何在不打开客户端端口的情况下通过HTTP/HTTPS完成双向通信?

How do I accomplish two way communication through HTTP/HTTPS without the need to open a port in the client?

注意:可以在服务器中打开端口80 ...对此没有问题.

Note : Port 80 can be opened in the server...no issues on that.

谢谢

推荐答案

您提到的那些系统的工作方式如下.他们首先尝试使客户端A和客户端B通过一系列不同的拓扑直接通信,这基本上要求它们之一允许传入的连接,如果失败的话,它们会退回到充当中间人的第三方.因此,客户端A与服务器进行对话,并向客户端B发送消息.然后,客户端A将发回给它的消息作为响应.客户端B将其消息发送到服务器,并且它从客户端A从服务器获取消息.这样,客户端A和客户端B总是会启动连接,并且不需要为传入流量打开端口.

Well those systems you mention work as follows. They first try to make client A and client B communicate directly via a range of different topologies which basically require one of them to allow incoming connections if that fails they fall back on a third party which acts as a man in the middle. So client A talks to the server and sends it messages for client B. Then Client A gets the messages addressed to it back in response. Client B sends it messages to the server and it's gets the message from client A back from the server. This way both client A and B always initiate the connection and don't need to have a port open for incoming traffic.

如果我对您的情况理解正确,那么您总是希望男人在中间.为此,您必须编写提供所有相关方法的WCF服务.例如

If I understand correctly in your case you would always want the man in the middle. In order to do this you would have to write a WCF service that provides all relevant methods. For instance things like

  • 无效的SendMessageToClient(向导senderId,Guid收件人ID,消息msg)
  • Message [] GetMessages(导航接收者ID)

然后让那些方法分别从某个地方(例如数据库或队列之类)存储和检索那些Message对象.

then have those methods respectively store and retrieve those Message objects from somewhere (like a database or a queue or something).

然后编写一个使用HTTP绑定连接到WCF服务的客户端,并调用服务器上的方法并处理结果.

Then write a client that connects to the WCF service using the HTTP binding and call the methods on the server and process the results.

希望您能理解

  • a),这不是一种非常有效的交流方式.
  • b),因为涉及的各方太多,并且通信是异步地存在于3个不同的过程中,因此很难进行测试,调试和理解正在发生的事情.
  • c),它在通信之上增加了一个额外的层,因此当您处理基础结构位以及何时使用通信时,您需要头脑清醒(最好在代码中)正在处理实际协议,clientA和clientB在Message对象中互相交谈.
  • a) this isn't a very efficient way to communicate.
  • b) that it's difficult to test and debug and understand whats going on since there are so many parties involved and communication is asynchronous living in 3 different processes.
  • c) it adds an extra layer ontop of the communication so you need to keep it clear for yourself in your head (and prefereably in code) when you are dealing with the infrastructure bits and when you are dealing with the actual protocol clientA and clientB speak to each other in the Message objects.

伪(代码)示例

在此示例中,我假设消息对象不过是一个字符串,并且唯一的命令是"whattimeisit",响应是字符串形式的本地时间

  • ClientA调用server.SendMessageToClient("clientA","clientB","whattimeisit");
  • 服务器将此消息存储在ID为1的数据库中
  • ClientB调用服务器GetMessages("clientB");
  • 服务器检索ID为1的消息
  • ClientB收到"whattimeisit"作为响应
  • ClientB调用server.SendMessageToClient("clientB","clientA","19:50:12");
  • 服务器将此消息存储在ID为2的数据库中
  • ClientA调用服务器GetMessages("clientA");
  • 服务器检索ID为2的消息
  • ClientA收到"19:50:12"作为回复
  • ClientA makes call to server.SendMessageToClient("clientA", "clientB", "whattimeisit");
  • Server stores this message in the database with ID 1
  • ClientB makes call to server GetMessages("clientB");
  • Server retrieves message with ID 1
  • ClientB recieves back "whattimeisit" as a response
  • ClientB makes call to server.SendMessageToClient("clientB", "clientA", "19:50:12");
  • Server stores this message in the database with ID 2
  • ClientA makes call to server GetMessages("clientA");
  • Server retrieves message with ID 2
  • ClientA recieves back "19:50:12" as a response

这篇关于WCF两种HTTP通信绕过防火墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆