简体   繁体   English

用于双工回调的WSDualHttpBinding

[英]WSDualHttpBinding for duplex callbacks

Would using WSDualHttpBinding for duplex callbacks work in real-world scenarios? 使用WSDualHttpBinding进行双工回调是否适用于实际场景? Say, I have a .NET application that uses a random port, would the service be able to resolve the client's base addresses and port for callbacks? 说,我有一个使用随机端口的.NET应用程序,该服务是否能够解析客户端的基地址和端口以进行回调?

A complete answer to your question depends on the "real-world scenario" being either an Intranet or an Internet scenario. 对您的问题的完整答案取决于“真实场景”是Intranet还是Internet场景。 Although WSDualHttpBinding works in both scenarios there are specifics to be aware of: 尽管WSDualHttpBinding在两种情况下都有效,但有一些细节需要注意:

Intranet 内部网

WSDualHttpBinding will work with your .NET application using a preconfigured custom port in an Intranet scenario and "Yes" the service will be able to resolve the client's base addresses and port for callbacks: exactly how is explained below. WSDualHttpBinding将使用Intranet场景中的预配置自定义端口与您的.NET应用程序一起使用,并且“是”该服务将能够解析客户端的基本地址和端口以进行回调:具体如何解释如下。 The reason it's explained below is that WSDualHttpBinding is primarily designed to be used over the Internet. 下面解释的原因是WSDualHttpBinding主要用于在Internet上使用。

Duplex callbacks in an Intranet scenario when you can use WCF on both client and server is best achieved by using NetTcpBinding or NetNamedPipeBinding. 当您可以在客户端和服务器上使用WCF时,Intranet方案中的双工回调最好通过使用NetTcpBinding或NetNamedPipeBinding来实现。 These bindings use TCP and ICP respectively as transport (rather than HTTP) and a custom binary encoding which is why WCF is required on both sides. 这些绑定分别使用TCP和ICP作为传输(而不是HTTP)和自定义二进制编码,这就是双方都需要WCF的原因。 For calls-back to the client the same channel used to connect to the Service via the Binding is re-used without requiring a new port to be opened. 对于回叫客户端,重新使用用于通过Binding连接到服务的相同通道,而无需打开新端口。

Internet 互联网

In an Internet scenario valid HTTP requests and responses only travel in one direction, HTTP is designed as a one-way protocol. 在Internet方案中,有效的HTTP请求和响应仅在一个方向上传播,HTTP被设计为单向协议。 When using the WSDualHttpBinding WCF therefore creates a seperate HTTP channel for callbacks. 使用WSDualHttpBinding时,WCF会为回调创建一个单独的HTTP通道。 In answer to your second question: the destination address for this call-back to the client is composed of the client machine hostname and port 80 by default. 回答第二个问题:默认情况下,回调客户端的目标地址由客户端计算机主机名和端口80组成。 If the client is a development machine for example and has IIS installed, port 80 will be exclusively reserved in some scenarios which will cause conflicts with your prototype application. 例如,如果客户端是开发计算机并且安装了IIS,则端口80将在某些情况下专门保留,这将导致与原型应用程序冲突。 This is what this blog post presents a solution for and what the ClientBaseAddress property is designed to help with. 这篇博客文章提供了解决方案以及ClientBaseAddress属性旨在帮助的内容。 Regardless of which port you go with - the default or a custom one, you must ensure all firewalls and routers on both sides are configured correctly to allow both the outgoing channel and the seperate callback channel to be established. 无论您使用哪个端口 - 默认端口或自定义端口,都必须确保双方的所有防火墙和路由器都已正确配置,以允许建立传出通道和单独的回调通道。

A .NET application can also denote a Silverlight application. .NET应用程序也可以表示Silverlight应用程序。 Because of the fact that a Silverlight application running in a browser cannot accept new incoming HTTP connections, WSDualHttpBinding with it's seperate back channel will not work. 由于在浏览器中运行的Silverlight应用程序无法接受新的传入HTTP连接,因此WSDualHttpBinding与其单独的反向通道将无法正常工作。 Hence PollingDuplexHttpBinding was created firstly in Silverlight 2 which can be thought of as a clever 'trick' to get around the fact that HTTP is unidirectional by keeping the request channel open for a long time (long polling) and using it as a back channel for calls back to the client. 因此PollingDuplexHttpBinding首先在Silverlight 2中创建,可以被认为是一个聪明的“技巧”,通过长时间保持请求通道打开(长轮询)并将其用作后向通道来解决HTTP是单向的这一事实。回电给客户。 This has a number of implications on both the client and server side particularly relevant to scaling, for more detail please see this post from my blog . 这对客户端和服务器端都有很多影响,特别是与扩展有关,更多细节请参阅我的博客中的这篇文章

With an idea of your particular "real-world scenario" and your use-cases hopefully this will help you work out the correct binding to use for duplex callbacks. 通过了解您特定的“真实场景”和您的用例,希望这可以帮助您确定用于双工回调的正确绑定。

If it's an application behind a firewall, theoretically yes. 如果它是防火墙后面的应用程序,理论上是的。 It depends on what you mean by "real world"; 这取决于你对“现实世界”的意思; if by that you mean "high performance" perhaps NetTcpBinding is a better appraoch. 如果你的意思是“高性能”,也许NetTcpBinding是一个更好的appraoch。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM