通过 Internet 传输数据的最佳方法(针对 .NET 开发人员)

发布于 2024-07-29 04:47:04 字数 515 浏览 3 评论 0 原文

我需要从服务器读取一些数据,通过互联网(无VPN)传输它,并将其写入另一台服务器的磁盘。 我本可以想到很多选择,但最终我实现了:

  1. 发送方作为 Windows 服务,每 X 分钟发送新数据
  2. 接收方作为 WCF 自托管服务,带有 WSHttpBinding。
  3. 数据作为字符串传输,这是序列化为 XML 的对象。

但是在我这样做之后,我意识到有很多方法可以做到这一点:

  1. 其他协议,例如 FTP。
  2. http://msdn.microsoft.com/en-us/ 中列出的其他绑定library/ms731092.aspx
  3. 其他参数类型,例如原始对象类型。

我想知道这些选项是否会带来更快、更可靠或更安全的传输。 你会推荐什么?

I need to read some data from a server, transfer it over the internet (no VPN), and write it to the disk of another server. I could have thought many choices, but in the end I implemented:

  1. The sender as windows service, that sends new data every X minutes
  2. The receiver as a WCF self hosted service, with WSHttpBinding.
  3. The data being transfered as a string, which is the object serialized to XML

But after I done that, I realized that there are many ways to do that:

  1. Other protocols such as FTP.
  2. Other bindings listed in http://msdn.microsoft.com/en-us/library/ms731092.aspx
  3. Other parameter types, such as the original object type.

And I wonder if any of these options would result in a faster, more reliable or more secure transfer. What would you recommend?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

千寻… 2024-08-05 04:47:04

如果可能的话,SFTP(SSH 文件传输协议)会得到我的投票。

几乎通过 SSH 连接建立 FTP 隧道。

...您还可以尝试创建符合 WS-Security 策略的 Web 服务,以实现基于消息的安全性(根据您使用的模型,您的消息使用从用户名/密码对到 X.509 证书的任何内容进行加密)。

当现成的包/协议可以工作并且完全符合您的目的时,构建自定义的东西似乎需要做很多工作。

SFTP (SSH File Transfer Protocol) gets my vote if it's a possibility.

Pretty much tunnels FTP through an SSH connection.

...you could also try creating web services that conform to the WS-Security policy for message based security (depending on the model you go with, your message is encrypted using anything from username/password pair to an X.509 Cert).

That just seems like a lot of work to build something custom when an off the shelf package/protocol would work and is perfectly legit for your purposes.

半葬歌 2024-08-05 04:47:04

在安全性方面,您可以利用 System.Security。 Cryptography.CryptoStream 在您通过网络传输数据时提供一层加密。

In terms of security, you could leverage System.Security.Cryptography.CryptoStream to provide a layer of encryption when you're passing data over the wire.

Oo萌小芽oO 2024-08-05 04:47:04

发件人是相当开放的——几乎任何选择都是好的。

对于接收者,可以考虑的一个选择是 HttpHandler —— 只是 ASP.NET 项目中的一个 ashx 文件。 您可以使用任何想要向接收者提供选项/信息的自定义 http 标头,然后数据只是 HTTP 请求的有效负载。 您无需通过文本编码来增加数据大小,安全性是通过 HTTPS 内置的。 这非常简单。

唯一的缺点是,如果您想实现某种“断开的连接,从我中断的功能中恢复”,这仍然是可能的,但有点困难——使用专门的定制服务可能会更容易。

The sender is pretty wide open -- pretty much any choice would be good there.

For a receiver, one option to consider is an HttpHandler -- just an ashx file in an ASP.NET project. You can use whatever custom http headers you want to provide options/information to the receiver, and then the data is just the payload of the HTTP request. You don't need to increase the size of your data by text encoding it, security is built in with HTTPS. It's pretty drop-dead simple.

The only downside would be if you wanted to implement some sort of "broken connection, pick up where I left off functionality" which is still possible but a little difficult -- that might be easier with a dedicated custom service.

玩心态 2024-08-05 04:47:04

我使用 Google Protocol Buffers。 很简单,为它编写一个套接字层即可。

它非常紧凑、支持多语言、速度快,最重要的是,添加数据字段很简单,而且不会破坏兼容性。

查看由 protobuf-net .com/users/23354/marc-gravell">Marc Gravell,Stack Overflow 的定期贡献者。

I use Google Protocol Buffers. Simple enough to write a socket layer for it.

It's very compact, multi-language, fast, and best of all, adding data fields is trivial, without breaking compatibility.

Check out protobuf-net written by Marc Gravell, who is a regular contributor on Stack overflow.

開玄 2024-08-05 04:47:04

基于您只想每分钟传输 1MB、不需要安全性的事实,并且由于您说双方都运行 Windows,所以我只需使用 WCF 和 netTcpBinding。 这将通过 TCP/IP 以二进制形式发送数据。

没有 SOAP、没有 XML、没有 HTTP 开销。

Based on the fact that you only want to transfer 1MB per minute, with no security required, and since you said both sides are running Windows, I'd simply use WCF and netTcpBinding. That would send the data as binary over TCP/IP.

No SOAP, no XML, not HTTP overhead.

琴流音 2024-08-05 04:47:04

如果您使用的是 Windows 服务器,您还可以使用 MSMQ 并获取消息传递保证、交易、可靠性和一大堆其他功能。 它公开 HTTP 端点,并且很容易从 .NET

If you are working with Windows servers you can also use MSMQ and get message delivery guarantees, transactions, reliability and a whole bunch of other features. It exposes HTTP endpoints and is pretty easy to access and use from .NET

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文