wcfrestduplexwebhttpbindingwcf-callbacks

Consuming a WCF Duplex service inside of a RESTful service


Suppose I wanted to create a WCF WebHTTP service ("ServiceREST") that had a reference to a duplex service ("ServiceDuplex"). ServiceDuplex requires implementations of certain callback members to deliver data that is requested from it. For example, a call to GetCustomers on ServiceDuplex triggers a method on that service that serves the customers back to the client via a callback "ReceiveCustomers".

That being said, suppose I wanted a method "GetSingleCustomer" on ServiceREST. Assuming all data is being retrieved on demand (rather than caching after startup), I'd have to first call "GetCustomers" from ServiceDuplex and wait for my collection to be filled inside of the callback I implement before I can search for the single customer I need.

Since webHttp doesn't support callbacks to the client, I'm forced to use something like an AutoResetEvent inside of my GET (GetSingleCustomer) call until the duplex's callback fills the collection.

Is there a "best practice" for what I'm trying to do, or is what I'm trying to do so wrong that such a practice hasn't been created?!

Thanks for the help.


Solution

  • Keep It Simple, the ServiceDuplex is not doing what is supossed to do, like make the calls Async, then why use it in the first place... just stick to only REST.