Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody. I am currently developing Client - Server app using WCF (duplex). Its clear enough how to handle callbacks in simple client. But my client must be complex multi-window application. For now i implement ICallback in main window. So in all child windows i make method, which i call inside callback methods to pass data to child. This way seems to me to be nasty. Especially for 3rd or 4th level children. So i want to learn is there a "best practice" or something like that to handle callbacks by many windows. May be it is the silly question, but i really cant find an answer.

What I have tried:

I try to "google" it, but didn't get any close enough result.
Posted
Updated 13-Dec-17 8:44am

1 solution

I've got an answer, but I've also got an alternative recommendation for WCF callbacks...

Passing data throughout an application should be done via services (in the DDD sense) and a bus. So what will happen is, the service object calling the WCF service will receive the callback information then send the appropriate message/object across the bus. Any other object in the application desiring the information will then simply subscribe to the bus.

For a simple application bus you can use a Reactive Subject. PRISM contains the EventAggregator which can be used as well; however, I personally highly discourage it's usage. Reactive objects are much more powerful in general and are easier to work with.

I've got some extensive articles on service buses if you want to check them out.

Global Service Bus Architecture in C#[^]

Unified Message Bus Framework - Part 1[^]

That all being said I would do away with WCF callbacks if possible and use a global service bus to send/relay information from processes if possible. It's much more easy to support loose coupling, asynchronous behaviors, scalability, etc.

Let's say, for example, I have an enterprise application and I update a User. Aren't their probably other applications that will need that updated information? How would it get to other applications if the WCF service call is local to the application? Well it can't... You'd have to create a completely separate service to poll the repository to see if an update has occurred. Not only is that cumbersome, but depending on how many applications require that information it can degrade performance.

Enter the service bus approach... You simply send out the User model object or something like a UserUpdatedMessage object. Anything that needs it, gets it.

It's a big adjustment admittedly, but hey... At least in the articles I provide an entire framework already built to handle it!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900