简体   繁体   English

WCF回调如何通过HTTP工作?

[英]How do WCF callbacks work over HTTP?

It is my understanding that in HTTP the client connects to the server and requests data. 据我所知,在HTTP中,客户端连接到服务器并请求数据。 The server cannot call the client. 服务器无法呼叫客户端。 If this is the case then how do WCF callbacks work? 如果是这种情况,那么WCF回调如何工作?

Thanks, 谢谢,

Joe

When used with HTTP transport the server does call the client. 与HTTP传输一起使用时,服务器调用客户端。 In order to get this to work the client must be on a public endpoint, so firewalls and what-have-you will need to be configured appropriately. 为了使其工作,客户端必须位于公共端点上,因此需要对防火墙和有什么需要进行适当配置。

From http://msdn.microsoft.com/en-us/magazine/cc163537.aspx : 来自http://msdn.microsoft.com/en-us/magazine/cc163537.aspx

Because of its connectionless nature, HTTP can't be used for callbacks and therefore you can't use callbacks over BasicHttpBinding or WSHttpBinding. 由于其无连接性,HTTP不能用于回调,因此您不能使用BasicHttpBinding或WSHttpBinding上的回调。 Windows Communication Foundation offers callback support for NetTcpBinding and NetNamedPipeBinding because the underlying transport is bidirectional. Windows Communication Foundation为NetTcpBinding和NetNamedPipeBinding提供回调支持,因为底层传输是双向的。 To support callbacks over HTTP, Windows Communication Foundation provides WSDualHttpBinding, which actually sets up two HTTP channels: one for the calls from the client to the service and one for the calls from the service to the client. 为了支持HTTP上的回调,Windows Communication Foundation提供了WSDualHttpBinding,它实际上设置了两个HTTP通道:一个用于从客户端到服务的调用,一个用于从服务到客户端的调用。

And from the reference for WSDualHttpBinding http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding.aspx : 并从WSDualHttpBinding的参考资料http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding.aspx

This binding requires that the client has a public URI that provides a callback endpoint for the service. 此绑定要求客户端具有公共URI,该URI为服务提供回调端点。 This is provided by the ClientBaseAddress. 这是由ClientBaseAddress提供的。 A dual binding exposes the IP address of the client to the service. 双重绑定将客户端的IP地址暴露给服务。 The client should use security to ensure that it only connects to services it trusts. 客户端应使用安全性来确保它只连接到它信任的服务。

A WCF Duplex HTTP client (for example when using a wsDualHttpBinding ) will start a server too, to listen to requests from the "real" server when it's calling back. WCF Duplex HTTP客户端(例如,当使用wsDualHttpBinding )也将启动服务器,以在其回叫时侦听来自“真实”服务器的请求。

So this won't work over NAT, to name one thing. 因此,这不会对NAT起作用,仅举一例。

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

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