JoeS
JoeS

Reputation: 231

How do WCF callbacks work over HTTP?

It is my understanding that in HTTP the client connects to the server and requests data. The server cannot call the client. If this is the case then how do WCF callbacks work?

Thanks,

Joe

Upvotes: 8

Views: 2735

Answers (2)

Jeremy McGee
Jeremy McGee

Reputation: 25200

When used with HTTP transport the server does call the client. 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:

Because of its connectionless nature, HTTP can't be used for callbacks and therefore you can't use callbacks over BasicHttpBinding or WSHttpBinding. Windows Communication Foundation offers callback support for NetTcpBinding and NetNamedPipeBinding because the underlying transport is bidirectional. 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.

And from the reference for 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. This is provided by the ClientBaseAddress. A dual binding exposes the IP address of the client to the service. The client should use security to ensure that it only connects to services it trusts.

Upvotes: 6

CodeCaster
CodeCaster

Reputation: 151604

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.

So this won't work over NAT, to name one thing.

Upvotes: 1

Related Questions