[英]Connecting over internet to WCF service using wsDualHttpBinding times out
Still on the WCF learning curve: 仍在WCF学习曲线上:
I've set up a self-hosted WCF Service (WSDualHttpBinding), which works fine on my own computer, which resides behind a firewall. 我已经设置了一个自托管的WCF服务(WSDualHttpBinding),它可以在我自己的计算机上运行,该计算机位于防火墙后面。 If I run the client on my own computer, everything works great.
如果我在自己的计算机上运行客户端,一切都很好。
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
. 现在我将客户端安装在网络外的计算机上,我试图通过动态DNS访问该服务,如下所示:
http://mydomain.dyndns.org:8000/MyService
: http://mydomain.dyndns.org:8000/MyService
: 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.
我现在可以在浏览器中看到该服务已启动。
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." 但是现在当我尝试在另一台机器上运行客户端时,我收到以下错误消息:“打开操作未在分配的超时00:01:00内完成。分配给此操作的时间可能是一部分更长的超时时间。“
I have disabled security on the service, so that's not it. 我已经禁用了服务的安全性,所以不是这样。 What else might be preventing the connection from happening?
还有什么可能阻止连接发生?
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
存在一个真正的问题,也就是大多数人连接到互联网的方式 - 正如你已经发现的那样,在路由器背后意味着,至少在IPv4中,NAT会破坏聚会。
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
更适合服务器到服务器的通信,其中设置是一次性的事情。
Instead of trying to get WSDualHttpBinding
to work, I suggest you switch to NetTcpBinding
. 我建议您切换到
NetTcpBinding
,而不是尝试让WSDualHttpBinding
工作。 Since both WSDualHttpBinding
and NetTcpBinding
are WCF-only, Microsoft-only, proprietary connection schemes, you're not losing much in the way of interoperability. 由于
WSDualHttpBinding
和NetTcpBinding
都是仅WCF,仅限Microsoft的专有连接方案,因此您在互操作性方面的损失并不大。 What you're gaining, on the other hand, is a lot: 另一方面,你获得的是很多:
NetTcpBinding
uses only a single connection, from the client to the server, while allowing two way communication like WSDualHttpBinding
. NetTcpBinding
仅使用从客户端到服务器的单个连接,同时允许双向通信,如WSDualHttpBinding
。 So there's no need to deal with port opening/forwarding on the client side - NAT is a non-issue. WSDualHttpBinding
. WSDualHttpBinding
使用的纯文本XML更紧凑。 Less data transfer means a better performing service. NetTcpBinding
, you can get instant notification of when a client disconnects, since a socket is closed. NetTcpBinding
,您可以立即获得客户端断开连接的通知,因为套接字已关闭。 No need to wait for a HTTP timeout like you do with WSDualHttpBinding
. WSDualHttpBinding
一样等待HTTP超时。 WSDualHttpBinding
, one of the two connections may drop while the other may still be active, having only one way communication. WSDualHttpBinding
,两个连接中的一个可能会丢弃而另一个可能仍处于活动状态,只有一种通信方式。 WCF has a way of dealing with that, but it's better to just avoid the issue in the first place. Switching to NetTcpBinding
usually only requires a configuration change - the code remains the same. 切换到
NetTcpBinding
通常只需要更改配置 - 代码保持不变。 It's simple, it's fast, it's much less of a hassle and most importantly - it just works. 这很简单,速度很快,不那么麻烦,最重要的是 - 它只是起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.