The three types of message exchange modes in WCF are discussed above, One-way,request/reply,duplex. The first two relatively simple, needless to say, duplex relatively complex, the above just to achieve a simple callback, in the real application, there are many noteworthy, this article on the combination of a practical example to discuss the specific application of duplex and very worthy of our attention.
The starting point of this article
By reading this article, you can understand the following knowledge:
How to implement an event broadcast based on duplex
Analysis of several problems in realizing duplex event broadcasting
A preliminary discussion of asynchronous
This article is suitable for readers
This article is a moderately difficult article that requires basic knowledge about WCF message exchange and Windows application development, and for WCF message exchange, read WCF from theory to Practice (7): Message Exchange Mode
How to implement an event broadcast based on duplex
Before discussing how to do this, look at what the example of this article is going to accomplish. The example in this article implements a simple distributed task management system that, in short, performs a task (job) on the server point, and renders the task's information to the client. It has the following characteristics:
By invoking the service-side accept (), the client can connect to the server and maintain the session.
At the time the client starts, it is possible to remotely invoke Getjobs () to get all the tasks in the current server and present them to the list control in the client form
The client can add a task to the server by calling AddJob (), and when the server completes the add operation, the event is raised to add completion and the event is broadcast to all clients
When a new task event broadcast is sent by the client server, the client adds the new task to the list control to render
The client can command the server to perform a specific task, and when the task begins execution and execution, the server ends up acting like a full client broadcast task, and the execution of the task and the broadcast of the event are performed asynchronously
After the client receives the broadcast, it can update the task information.
Unlike previous articles, this article first gives the effect of the final implementation