使用wsDualHttpBinding超时连接在互联网上的WCF服务 [英] Connecting over internet to WCF service using wsDualHttpBinding times out

查看:506
本文介绍了使用wsDualHttpBinding超时连接在互联网上的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仍是WCF学习曲线:

我已经建立了一个自托管WCF服务(WSDualHttpBinding),这我自己的电脑,它驻留在防火墙后面的工作正常。如果我将自己的计算机上运行客户端,一切都很正常。

I've set up a self-hosted WCF Service (WSDualHttpBinding), which works fine on my own computer, which resides behind a firewall. If I run the client on my own computer, everything works great.

现在我安装我的网络以外的计算机上的客户端,我想通过一个动态DNS访问服务,像这样: http://mydomain.dyndns.org:8000/为MyService 。我的端口转发问题在 previous问题得到照顾;我现在可以看到的服务是在我的浏览器。

Now I installed the client on a computer outside my network, and I'm trying to access the service via a dynamic DNS, like so: http://mydomain.dyndns.org:8000/MyService. My port forwarding issues were taken care of in a previous question; I can now see the service is up in my browser.

但现在当我尝试到其他机器上运行的客户端,我得到以下错误信息:开放的操作没有的00:01:00分配的超时时间内完成分配给此操作的时间可能有是一个较长超时的一部分。

But now when I try to run the client on the other machine, I get the following error message: "The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout."

我对残疾人服务的安全性,所以这不是它。还有什么可能是preventing的发生联系?

I have disabled security on the service, so that's not it. What else might be preventing the connection from happening?

推荐答案

有与 WSDualHttpBinding 一个真正的问题的方式和大多数人都连接到互联网 - 暂时落后一路由器是指,至少在IPv4中,具有NAT破坏了党,因为你已经发现了。

There's a real problem with WSDualHttpBinding and the way most people are connected to the internet - being behind a router means, at least with IPv4, having NAT ruin the party, as you've already discovered.

使用 WSDualHttpBinding ,你有两个连接:从客户机到服务器,从服务器到客户端

With WSDualHttpBinding, you have two connections: From the client to the server, and from the server to the client.

通常情况下,客户端到服务器的连接是不是一个大问题 - 这是大多数通信是如何在互联网上完成的。根据你的情况,看来你是在防火墙后面,你打开/转发所需的端口。但是,这并不解决第二连接的问题 - 从服务器到客户端。基本上,与第二个连接的情况是,客户机作为服务器,而服务器作为客户端。所以,你需要做相同的端口打开/转发与每个连接到您的服务客户端,因为它也充当服务器!当然,这是不合理的要求,使您的服务每一位用户。这就是为什么 WSDualHttpBinding 更适合于服务器到服务器的通信,其中的设置是一次性的事情。

Usually, the client-to-server connection isn't a big deal - that's how most communication is done over the internet. In your case, it seems that you were behind a firewall and you've opened/forwarded the needed ports. But that doesn't solve the problem of the second connection - from the server to the client. Basically what happens with that second connection is that the client acts as a server, and the server acts as a client. So you need to do the same port opening/forwarding with each and every client that connects to your service, because it also acts as a server! This is of course an unreasonable demand to make of every user of your service. That's why WSDualHttpBinding is more suited to server-to-server communications, where the setup is a one-time affair.

而不是试图让 WSDualHttpBinding 工作,我建议你改用 NetTcpBinding的。由于两个 WSDualHttpBinding NetTcpBinding的的WCF只,微软只,专有的连接方案,你不会损失太多在互联互通的方式。什么你获得,而另一方面,是不少:

Instead of trying to get WSDualHttpBinding to work, I suggest you switch to NetTcpBinding. Since both WSDualHttpBinding and NetTcpBinding are WCF-only, Microsoft-only, proprietary connection schemes, you're not losing much in the way of interoperability. What you're gaining, on the other hand, is a lot:


  1. NetTcpBinding的只使用一个单独的连接,从客户端到服务器,同时允许像 WSDualHttpBinding 双向通信。因此,有没有需要处理在客户端的端口打开/转发 - NAT是一个非问题

  2. 的通信协议是二进制和比 WSDualHttpBinding 使用纯文本XML更紧凑。较少的数据传输装置性能更好的服务。

  3. NetTcpBinding的,你可以当一个客户端断开连接的即时通知,因为套接字被关闭。无需等待HTTP超时像你 WSDualHttpBinding 做的。

  4. 的单一连接意味着什么可以不同步 - 以 WSDualHttpBinding ,两个连接中的一个可能会下降,而其他的可能仍然是积极的,只有一个双向通信。 WCF有一个处理的一种方式,但最好只是避免在首位的问题。

  1. NetTcpBinding uses only a single connection, from the client to the server, while allowing two way communication like WSDualHttpBinding. So there's no need to deal with port opening/forwarding on the client side - NAT is a non-issue.
  2. The communication protocol is binary and is more compact than the plain-text XML used in WSDualHttpBinding. Less data transfer means a better performing service.
  3. With NetTcpBinding, you can get instant notification of when a client disconnects, since a socket is closed. No need to wait for a HTTP timeout like you do with WSDualHttpBinding.
  4. A single connection means there nothing that can go out of sync - with WSDualHttpBinding, one of the two connections may drop while the other may still be active, having only one way communication. WCF has a way of dealing with that, but it's better to just avoid the issue in the first place.

切换到 NetTcpBinding的通常只需要更改配置 - 在code保持不变。这很简单,它的速度快,这是更麻烦了,最重要的 - 它只是工作

Switching to NetTcpBinding usually only requires a configuration change - the code remains the same. It's simple, it's fast, it's much less of a hassle and most importantly - it just works.

这篇关于使用wsDualHttpBinding超时连接在互联网上的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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