When would you use Duplex WCF service?

Technology CommunityCategory: WCFWhen would you use Duplex WCF service?
VietMX Staff asked 3 years ago

You need duplex if you want to implement callback pattern. Callback means that client does not know when some event happens in server. If you do not know when event happens you have two options to implement:

  • Polling – send requests every X minutes to check if event happened. Server should either return event details (if it happened) or return flag saying that you need to continue calling. Server also can return recommended timeout in advanced scenarios.
  • Callback – client sends some form of description what server should do if event happened. This may be pointer to function in C, delegate in .NET or endpoint schema in WCF. Server remembers that info and makes call from their side when time came. As you can see duplex/callback means that at some point server works as client (initiates communication) and this is a big game change.

WCF duplex communications may require special network configuration because in many cases network allows you to call external services (you work as client) but forbids external resources to call you (external service works as client). This is implemented for security purposes.