user1438082
user1438082

Reputation: 2748

why is wcf duplex required?

WCF duplex performs a callback after a method has run on the server that then runs code on the client.

If i want to execute a method on the client from the server at the push of a button on the server then i don't think WCF duplex is appropriate.

Why would i not just create a client and a server at each end of my 2 applications?

Upvotes: 0

Views: 230

Answers (2)

Mike Goodwin
Mike Goodwin

Reputation: 8880

I was one of the people that commented on your previous question so I probably owe you an answer here :o)

You have posted rather a lot of code and I have not looked at it in detail. However, in general terms, there is a reason for using wsDualHttpBinding and duplex contracts in general instead of more of a peer-to-peer approach where you have services on both sides, as follows:

The duplex approach is appropriate where you have a clearly defined server that is running permanently. This provides the hub of the interaction. The idea is that clients are in some way more transient than the server. The clients can start up and shut down or move location and the server does not need to be aware of them in advance. When the client starts up, it is pre-configured to know where the server is, so it can "register" itself with the server.

In contrast, the server does not need to be preconfigured to know where the clients are. It starts up and can run independently of any clients. It just accepts "registrations" from all clients that have valid credentials whenever they come online, and can continue to run after the client goes offline. Also, if the client moves, it just re-registers itself with the server at its new location.

So the server is in some sense a more "important" part of the system. No client can participate in the communication without the server, but the server can operate independently of any client.

To do this with WCF duplex service, you have to do some extra work yourself to implement the publish/subscribe behaviour. Fortunately, the MSFT Patterns and Practises team have provided some guidance on how to do it

http://msdn.microsoft.com/en-us/library/ms752254.aspx

This is fundamentally different from a genuine peer-to-peer approach where there is no well-defined hub (i.e. server) for the network and each node can come and go without affecting the overall functioning of the network.

Upvotes: 3

Gigi
Gigi

Reputation: 29441

WCF Duplex is used when you have a Publish/Subscribe setting (also known as the Observer Pattern). Let's say you have a service that subscribes for notifications of some sort (e.g. new email). Normally, you would need to check periodically for updates. Using WCF Duplex, the subscriber can be notified automatically by the publisher when there are updates.

Upvotes: 2

Related Questions